Я хочу заменить вхождения строк следующего формата на другие строки. Эта операция должна выполняться в цикле for.StringByReplacingOccurrencesOfString with options issue
Здесь fullString выглядит как этот
There are some other things ... Child_name_13 and Child_name_12 there are some other things ...... Child_name_1 some other things ... Child_name_12 some other things.. Child_name_6 some other things ... Child_name_7
То, что я хочу сделать, это заменить «Child_name_1», «Child_name_12», «Child_name_7» и т.д. с соответствующими именами детей возвращается из arrOfChildren.
Мой подход заключается в следующем.
for(int i=0; i<[arrOfChildren count]; i++){
NSString *strChildName = [[arrOf15Children objectAtIndex:i] objectForKey:@"Name"];
fullString = [fullString stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"child_name_%d",i+1] withString:strChildName options:NSCaseInsensitiveSearch range:NSMakeRange(0, [fullString length])];
}
Этот вопрос, я получаю на выходе что-то вроде этого (Допустим, имена детей, как Бен, Рэнди, Амилом, Sanj, Павла, Марка, Ayen, Sid, Дон, Юн Синь Синь, Nik, Джек)
There are some other things ... Ben3 and Ben2 there are some other things ...... Ben some other things ... Ben2 some other things.. Mark some other things ... Ayen
Но я хочу, чтобы это было как этот
There are some other things ...Nik and Xin there are some other things ...... Ben some other things ... Xin some other things.. Mark some other things ... Ayen
Я надеюсь, вы получите этот вопрос.
Проверьте мой ответ, он может выполнить лучше, чем регулярные выражения. –