Replace a substring with another substring

。_饼干妹妹 提交于 2019-12-20 11:09:18

问题


I want to replace the string "abc" to "def" each time it appears in my NSString object: "axcd abc amamam dff abc kdj abc"

How do I do that??

Thanks,

Sagiftw


回答1:


Try stringByReplacingOccurrencesOfString:withString:.

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



回答2:


Check out replacing regular expressions



来源:https://stackoverflow.com/questions/3613843/replace-a-substring-with-another-substring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!