1

I am building an app with a lot of urls being called from a MySQL server.

What I need to do for my app is take the textfield text and send it (which i already know how to do) BUT i need to replace the spaces with + (pluses)

gcamp
  • 14,622
  • 4
  • 54
  • 85
inVINCEable
  • 2,167
  • 3
  • 25
  • 49
  • 5
    What you *probably* need to do is URL encode the text, not take a piecemeal approach where you encode spaces as + signs, then find the next character that's also illegal. I've found a [blog post](http://madebymany.com/blog/url-encoding-an-nsstring-on-ios) that describes doing so under iOS. – Damien_The_Unbeliever Sep 02 '11 at 13:51
  • @Damien_The_Unbeliever I +1'd you because you're right about the URL encoding, but you should provide an answer here in addition to linking to the blog post =) – Cameron Spickert Sep 02 '11 at 14:08

1 Answers1

12

Try with the string method - (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement;

str=[str stringByReplacingOccurrencesOfString:@" " withString:@"+"];
aViNaSh
  • 1,318
  • 14
  • 15