I have to check out whether a russian character is present in a NSString or not.
I am using the following code for that:
NSCharacterSet * set =
[[NSCharacterSet characterSetWithCharactersInString:@"БГДЁЖИЙЛПФХЦЧШЩЪЫЭЮЯ"]
invertedSet];
BOOL check = ([nameValue rangeOfCharacterFromSet:set].location == NSNotFound);
return check;
But it is always returning FALSE.
Can anybody give me an idea what is wrong in my code?
Thanks
Currently, your condition checks that non-Russian (technically, non-Cyrillic) characters are absent from the string, not that Cyrillic characters are present in the string. Your code will return
YESonly for strings that are composed entirely of Cyrillic characters that do not have an equivalent character in the Latin alphabet1.To fix this problem, remove the inversion, and invert the check, like this:
1 You have forgotten to include the soft stop
Ьin your list, it looks like a lower-caseb, but it is not the same character.