开发者

Replace a char into NSString

开发者 https://www.devze.com 2023-01-05 05:53 出处:网络
I want simply replace all occourrencies of \"+\" with a blank \" \" char... I tried some开发者_如何学编程 sample listed here, also used NSSMutableString, but the program crash...

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号