如何将UITextfield输入与不同的字符串进行比较? [英] How do I compare UITextfield input to different strings?
本文介绍了如何将UITextfield输入与不同的字符串进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将UITextfield的输入值与其他一些字符串进行比较.这是我的猜测.
I want to compare the value of the input from a UITextfield to some other strings. Here's my guessing.
if ([textfield.text isEqualToString:@"First" || @"Second" || @"Third"]) {
// do something
}
有什么更好的方法吗?
推荐答案
在有一系列对象(例如您的示例)的情况下,应将其添加到数组中并测试其在数组中的存在:
In a situation where you have a series of objects such as your example, you would add then to an array and test its existence in the array:
示例
NSMutableArray *arr = [[[NSMutableArray alloc] init] autorelease];
[arr addObject:@"First"];
[arr addObject:@"Second"];
[arr addObject:@"Third"];
if ([arr containsObject:textField.text])
{
// do something
}
这篇关于如何将UITextfield输入与不同的字符串进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文