-4

句子中有空格时如何添加加号(+)?

例子:

Hello how are you doing

我想要的是:

Hello+how+are+you+doing
4

4 回答 4

7

尝试:

NSString *str = @"Hello how are you doing";
str = [str stringByReplacingOccurrencesOfString:@" " withString:@"+"];
于 2013-02-13T13:50:25.830 回答
0

尝试stringByReplacingOccurrencesOfString:withString:来自 NSString 类的方法

于 2013-02-13T13:51:43.333 回答
0

你可以这样做:

NSString *helloWorld = @"Hello How are you doing";
NSString *alteredString = [helloWorld stringByReplacingOccurrencesOfString:@" " withString:@"+"];

stringByReplacingOccurrencesOfString:@" " withString:@"+"就是你在这里看到的。

祝你好运。

于 2013-02-13T13:51:52.183 回答
0
 NSMutableString *nstring = [NSMutableString stringWithFormat:@"Hello how are you doing"];

   NSString *newString =  [nstring stringByReplacingOccurrencesOfString:@" " withString:@"+"];
    NSLog(@"%@",newString);
于 2013-02-13T13:58:20.193 回答