I need to add the string @"d" after "id="

Example =

url = @"id=63488320543140151742289377"

needs to be

url = @"id=d63488320543140151742289377"

I have tried this:

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

but not work

有帮助吗?

解决方案

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

其他提示

stringByReplacingCharactersInRange returns a string. Your code should work if you assign the new string that's returned to some variable (e.g. url = [url stringByReplacingCharactersInRange:range withString:@"id=d"];)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top