I want simply replace all occourrencies of "+" with a blank " " char... I tried some sample listed here, also used NSSMutableString, but the program crash... what's the best way to replace a char from another?? thanks
Asked
Active
Viewed 3,105 times
2 Answers
13
If you want to replace with a mutable string (NSMutableString) in-place:
[theMutableString replaceOccurrencesOfString:@"+"
withString:@" "
options:0
range:NSMakeRange(0, [theMutableString length])]
If you want to create a new immutable string (NSString):
NSString* newString = [theString stringByReplacingOccurrencesOfString:@"+"
withString:@" "];

kennytm
- 510,854
- 105
- 1,084
- 1,005
-
thankyou! it works fine! I don't know yesterday what was the problem.. now is ok! – ghiboz Jun 29 '10 at 20:55
-
Do I have to release the string explicitly later? – Roger C S Wernersson Dec 05 '12 at 15:51
1
NSString *firstString = @"I'm a noob at Objective-C", *finalString;
finalString = [[firstString stringByReplacingOccurrencesOfString:@"O" withString:@"0"] stringByReplacingOccurrencesOfString:@"o" withString:@"0"];
Got the code from here!

Arman Ortega
- 3,003
- 1
- 30
- 28

Bogdan Constantinescu
- 5,296
- 4
- 39
- 50