I am trying to replace an array of characters from within an NSString.
For example if we have this string:
NSString *s = @"number one and two and three";
NSArray *A1 = [NSArray arrayWithObjects:@"one",@"two",@"three", nil];
NSArray *A2 = [NSArray arrayWithObjects:@"1",@"2",@"3", nil];
I need to replace all members of that string found within A1 with the corresponding members of A2.
NSString
has an instance method calledstringByReplacingOccurencesOfString:
see the Apple Documentation for NSString for help on the actual method - code wise you could try the below code.As noted in comments this code could return "bone" as "b1". To get around this you could I suppose replace your arrays with:
Note I all I have done is added in the spaces so if you had "bone" it will not replace it to "b1".