views:

135

answers:

2

Hi all! 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

+2  A: 

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
thankyou! it works fine! I don't know yesterday what was the problem.. now is ok!
ghiboz
A: 
NSString *firstString = @"I'm a noob at Objective-C", *finalString;

finalString = [[firstString stringByReplacingOccurancesOfString:@"O" withString:@"0"] stringByReplacingOccurancesOfString:@"o" withString:@"0"];

Got the code from here!

Bogdan Constantinescu