Replace a substring with another substring

后端 未结 2 965
悲&欢浪女
悲&欢浪女 2021-02-05 03:00

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,

<
2条回答
  •  北恋
    北恋 (楼主)
    2021-02-05 03:43

    Try stringByReplacingOccurrencesOfString:withString:.

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

提交回复
热议问题