我有一个有趣的小问题。 所以我需要创建一个if语句,它可以检测数组中的单词后面是否有单词
所以我的代码是
NSArray *words = [texfield.text componentsSeparatedByString:@" "]; int index = [words indexOfObject:@"string"];我不确定我是否必须这样做
NSString*needle=words[index+1]; if (needle isEqualto @"") { //There is a word after @"string"; }我该怎么办?
如何确定@“string”后面是否有单词?
我感谢所有的帮助!! :)
I have a fun little tricky problem. So I need to create an if statement that can detect if there is a word after a word in an array
so my code is
NSArray *words = [texfield.text componentsSeparatedByString:@" "]; int index = [words indexOfObject:@"string"];I am not sure if I have to do something like
NSString*needle=words[index+1]; if (needle isEqualto @"") { //There is a word after @"string"; }What should I do?
How can I determine is there is a word after @"string"?
I appreciate all the help!! :)
最满意答案
方法componentsSeparatedByString:将通过输入NSString分隔所有组件。
你的例子。 NSArray *words = [texfield.text componentsSeparatedByString:@" "];
将所有字符串分隔为" " 。 所以只需检查一下
NSInteger afterIndex = index+1; if(afterIndex<words.count) NSInteger afterIndex = index+1; if(afterIndex<words.count)如果是,则可以使用NSString 。
Method componentsSeparatedByString: will give all components separated by input NSString.
Your eg. NSArray *words = [texfield.text componentsSeparatedByString:@" "];
will have all string separated by " ". So just check if any
NSInteger afterIndex = index+1; if(afterIndex<words.count) if Yes, you have NSStringavailable.
更多推荐
发布评论