2012-11-12 222 views
2

我需要 「ID =」 之後添加字符串@ 「d」替換字符串不行

示例=

url = @"id=63488320543140151742289377" 

需求是

url = @"id=d63488320543140151742289377" 

我已經試過這樣:

NSRange range = [url rangeOfString:@"id="]; 
[url stringByReplacingCharactersInRange:range withString:@"id=d"]; 

但不工作

回答

7
url = [url stringByReplacingOccurrencesOfString:@"id=" withString:@"id=d"]; 
+0

thx a loot ....! – Ladessa

2

stringByReplacingCharactersInRange返回一個字符串。如果您將新字符串分配給某個變量(例如url = [url stringByReplacingCharactersInRange:range withString:@"id=d"];

+0

我已經嘗試過stringByReplacingOccurrencesOfString:@「id =」withString:@「id = d」];但忘了url = ... thx! – Ladessa