所以我想测试2 1NSString
以查看它们在我输入时是否相同:
NSString *theOriginalString = [NSString stringWithFormat:@"Superman"];
NSString *theTypedString = [textView string];
我想查看TypedString
输入时是否错误,以便在有人输入错误答案时弹出警告。
提前谢谢你。
答案 0 :(得分:5)
使用isEqualToString:
确定两个字符串是否相同,在这种情况下请执行以下操作:
if ([theOriginalString isEqualToString:theTypedString] == NO) {
NSLog(@"The Strings are Different, wrong answer!");
} else {
NSLog(@"The Strings are the Same, correct answer!");
}
修改强>
如果你想确定他们到目前为止输入的内容是对的,试试这个:
if ([theOriginalString hasPrefix:theTypedString] == NO) {
NSLog(@"The Strings are Different, wrong answer!");
} else {
NSLog(@"The Strings are the Same, correct answer!");
}