如何找出一个长字符串包含一个单词obj c,iphone [英] how to find out is a long string contatins a word obj c, iphone
问题描述
我有一个长字符串,其中包含文本框中所有输入的单词"的运行列表.我希望能够针对一个单词字符串检查长字符串,以查看长字符串是否包含短字符串中的单词.
I have a long string that has a running list of all the "words entered" in the text box. I want to be able to check the long string against a one word string to see if the long string contains the word in the short string.
有什么想法吗?
我已经尝试过此操作以及其他一些操作,其中newString是长字符串,而currentTextrightnow是短字符串.
I've tried this and a few other things, where newString is the long string and currentTextrightnow is the short string.
textRange =[newString rangeOfString:currentTextrightnow];
NSLog(@"currenttextright now is %@", currentTextrightnow);
if(textRange.location != NSNotFound)
{
NSLog(@"Does contatin the substring");
}
推荐答案
我遇到了与您相同的问题.您实际上在做对(如果textRange是NSRange类型),但是问题是NSNotFound无法按预期工作(可能是一个错误).相反,您可以
I had the same problem as you did. You are actually doing it right (if textRange is of type NSRange) but the problem is NSNotFound doesn't work as expected (might be a bug). Instead you can do
if (range.length > 0) {
//it found it
} else {
// it didn't find it
}
希望有帮助.
这篇关于如何找出一个长字符串包含一个单词obj c,iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!