开发者

Replace a substring with another substring

开发者 https://www.devze.com 2023-01-13 18:17 出处:网络
I want to replace the string \"abc\" to \"def\" each time it 开发者_如何学Goappears in my NSString object:

I want to replace the string "abc" to "def" each time it 开发者_如何学Goappears in my NSString object: "axcd abc amamam dff abc kdj abc"

How do I do that??

Thanks,

Sagiftw


Try stringByReplacingOccurrencesOfString:withString:.

NSString* foo = @"axvc abc amamam dff abc kjd abc";
NSString* bar = [foo stringByReplacingOccurrencesOfString:@"abc" withString:@"def"];
NSLog("%@", bar);


Check out replacing regular expressions

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号