句子中有空格时如何添加加号(+)?
例子:
Hello how are you doing
我想要的是:
Hello+how+are+you+doing
句子中有空格时如何添加加号(+)?
例子:
Hello how are you doing
我想要的是:
Hello+how+are+you+doing
尝试:
NSString *str = @"Hello how are you doing";
str = [str stringByReplacingOccurrencesOfString:@" " withString:@"+"];
尝试stringByReplacingOccurrencesOfString:withString:
来自 NSString 类的方法
你可以这样做:
NSString *helloWorld = @"Hello How are you doing";
NSString *alteredString = [helloWorld stringByReplacingOccurrencesOfString:@" " withString:@"+"];
stringByReplacingOccurrencesOfString:@" " withString:@"+"
就是你在这里看到的。
祝你好运。
NSMutableString *nstring = [NSMutableString stringWithFormat:@"Hello how are you doing"];
NSString *newString = [nstring stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSLog(@"%@",newString);