检查一个单词后面是否有单词(NSSTRING)(Check if there is a word after a word (NSSTRING))

编程入门 行业动态 更新时间:2024-10-26 08:33:46
检查一个单词后面是否有单词(NSSTRING)(Check if there is a word after a word (NSSTRING))

我有一个有趣的小问题。 所以我需要创建一个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.

更多推荐

本文发布于:2023-07-06 07:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047552.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单词   NSSTRING   word   Check

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!