views:

52

answers:

2

Hi,

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

A: 

Check out replacing regular expressions

Dave McClelland
+5  A: 

Try stringByReplacingOccurrencesOfString:withString:.

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

EDIT There was a typo in the method name. I've fixed it.

zneak
Thanks! It works perfectly!