Question

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

Was it helpful?

Solution

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:@" "];

OTHER TIPS

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top