Replace a char into NSString
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
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:@" "];
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!
精彩评论