5

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

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Bobj-C
  • 5,276
  • 9
  • 47
  • 83
  • 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
  • 87,846
  • 14
  • 132
  • 192
1
return [thatString stringByReplacingOccurrencesOfString:@" " withString:@"+"];

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

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005