0
我在我的建议数组中匹配了一个子字符串来创建自动填充文本字段。在Swift中搜索字符串中的子字符串不起作用
func searchAutocompleteEntriesWithSubstring(substring: String)
{
autocompleteUrls.removeAll(keepCapacity: false)
for curString in countries
{
let myString:NSString! = curString as NSString
let substringRange :NSRange! = myString.rangeOfString(substring)
if (substringRange.location == 0)
{
autocompleteUrls.append(curString)
}
}
autocompleteTableView.reloadData()
}
但是,如果国家我寻找是印度,我开始从“NDIA”搜索,它没有得到建议,应该得到这一点。
的[?如何检查是否字符串包含在斯威夫特另一个字符串(可能的复制http://stackoverflow.com/questions/24034043/how-do-i -check-if-a-string-contains-another-string-in-swift) –
想一想:if(substringRange.location == 0)是什么时候? –
你们是否真的在阅读问题或只是回答问题?请再次阅读我的确切要求。我想匹配确切的字符明智....如果我开始搜索“dia”,搜索结果也应该返回INDIA – Saty