NSString * currentWord;
currentWord = Text.text;
UITextChecker* checker = [[UITextChecker alloc] init];
NSString* preferredLanguage = [[UITextChecker availableLanguages] objectAtIndex:0];
NSRange range;
range = [checker rangeOfMisspelledWordInString:currentWord
range:NSMakeRange(0, [currentWord length])
startingAt:0
wrap:NO
language:preferredLanguage];
if (range.location == NSNotFound)
{
NSLog(@"Word found");
}
else
{
NSLog(@"Word not found");
}//在这里我使用了UITextChecker函数,即使是错误的单词,上面的函数也会显示正确的单词声明,例如:像abcd,bcde,cdef,CAPs这样的错误单词,请帮助我这背后的原因是什么。有没有其他选择来解决这个问题?
提前感谢
发布于 2013-09-26 01:22:03
UITextChecker *Checker = [[UITextChecker alloc] init];
NSRange range = NSMakeRange(0, inputWord.length);
NSRange misspelledRange = [Checker rangeOfMisspelledWordInString:[Sentence lowercaseString] range:range startingAt:0 wrap:NO language:@"en_IN"];
bool isValidWord = misspelledRange.location == NSNotFound;
//NSLog(@"----%i", misspelledRange.location);
if (isValidWord)
{
isValidWord = [self checkIfWordExistsInSuggestedSpellings:Sentence];
NSLog(@"++++%d", isValidWord);
}
return isValidWord;
}
else
{
NSLog(@"Invalid word");
return false;
}https://stackoverflow.com/questions/17527200
复制相似问题