我从用户那里获取了一个字符串,并对其进行了一些迭代。
例如用户输入文字@“今天天气真好。”;
"the wether is beatifullll tdy"
当用户输入or"th weather is beatttiful tooodayy"
或时,我想进行相同的迭代"the weatherrr iss beautiful toda"
。
这是我的代码:
// (str is the user's text)
if ([str rangeOfString:@"hello" options:NSCaseInsensitiveSearch].location != NSNotFound) {
// when user entered helloo I want make to same iteration,
// but in this case the program goes else part.
[array insertObject:@"hello" atIndex:s];
} else if ([str rangeOfString:@"You are so beautiful" options:NSCaseInsensitiveSearch].location != NSNotFound ) {
[dizi insertObject:@"I know, Thanks" atIndex:s];
} else if ([str rangeOfString:@"Have Lunch?" options:NSCaseInsensitiveSearch].location != NSNotFound) {
[array insertObject:@"Yes,I have" atIndex:s];
} else {
[array insertObject:@"please,speak english" atIndex:s];
}