Replace a substring with another substring

后端 未结 2 964
悲&欢浪女
悲&欢浪女 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);
    
    0 讨论(0)
  • 2021-02-05 04:03

    Check out replacing regular expressions

    0 讨论(0)
提交回复
热议问题