Replace char with NSString

I just want to replace all the attributes “+” with a space “” char ... I tried some of the examples listed here, also used NSSMutableString, but the program crashed ... what's the best way to replace char from another? thanks

+6
iphone nsstring nsmutablestring str-replace
source share
2 answers

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:@" "]; 
+13
source share
 NSString *firstString = @"I'm a noob at Objective-C", *finalString; finalString = [[firstString stringByReplacingOccurrencesOfString:@"O" withString:@"0"] stringByReplacingOccurrencesOfString:@"o" withString:@"0"]; 

Got the code here !

+1
source share

All Articles