2013-02-13 44 views

回答

7

嘗試:

NSString *str = @"Hello how are you doing"; 
str = [str stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 
+2

+1不錯超快的答案 – 2013-02-13 13:52:30

0

嘗試從NSString類stringByReplacingOccurrencesOfString:withString:方法

0

你可以做什麼像這樣:

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

stringByReplacingOccurrencesOfString:@" " withString:@"+"特別是你在這裏看到的。

祝你好運。

0
NSMutableString *nstring = [NSMutableString stringWithFormat:@"Hello how are you doing"]; 

    NSString *newString = [nstring stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 
    NSLog(@"%@",newString); 
+0

這並不是說這是錯的,但爲什麼一個NSMutbaleString? – Josiah 2013-02-13 14:00:24

+0

@vikingosegundo然而,他並沒有修改字符串本身,而是創建了一個新的,已更改的實例。爲此,不需要可變字符串。 – 2013-02-13 14:07:51

+0

@ H2CO3,哦,我應該回去睡覺。 – vikingosegundo 2013-02-13 14:08:25