boucle dans le tableau et remplacer chaque personnage à son tour:
// Get the two arrays of characters to replace and their replacements
NSArray *fromArray = [NSArray arrayWithObjects:@"a", @"b", @"c", @"d", @"e", nil];
NSArray *toArray = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", nil];
// Make a mutable version of our string
NSMutableString *newString = [NSMutableString stringWithString:@"Hello World"];
// Deal with each replacement in turn
for (uint n = 0; n < [fromArray count]; ++n)
[newString replaceOccurrencesOfString:[fromArray objectAtIndex:n] withString:[toArray objectAtIndex:n] options:NSLiteralSearch range:NSMakeRange(0, [newString length])];
// Output the new string
NSLog(@"%@", newString);
Ce code n'est pas grand bien - si les deux tableaux sont différentes longueurs?
Merci non, ils avoir la même longueur. – mamrezo
@mamrezo vous feriez mieux d'examiner l'efficacité ici et peut-être l'exactitude si vous pouvez avoir des substitutions qui se chevauchent – rano