5

hey all i want a code the replace whitespaces by a + sign in objective-c

Gilles 'SO- stop being evil'
  • 98,216
  • 36
  • 202
  • 244
Bobj-C
  • 5,131
  • 8
  • 45
  • 79
  • possible duplicate of [Replace multiple characters in a string in Objective-C?](http://stackoverflow.com/questions/713918/replace-multiple-characters-in-a-string-in-objective-c) – thelost Aug 14 '10 at 14:00

2 Answers2

17

In case you are asking this because you need to encode URLs, use this

NSString* escapedUrlString =
  [unescapedString stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];

If you just need space to +, use

[str stringByReplacingOccurrencesOfString:@" " withString:@"+"];
Lou Franco
  • 85,695
  • 14
  • 129
  • 186
1
return [thatString stringByReplacingOccurrencesOfString:@" " withString:@"+"];

If your real target is to escape URL component, use the -stringByAddingPercentEscapesUsingEncoding: method instead.

kennytm
  • 491,404
  • 99
  • 1,053
  • 989