Saturday, 31 August 2013

NSMutableArray with Cyrillic text

NSMutableArray with Cyrillic text

I try to load words from a txt file using following code:
NSURL *filePath = [[NSBundle mainBundle] URLForResource:@"testFile"
withExtension:@"txt"];
NSString*stringPath = [filePath absoluteString];
NSData *drfData = [NSData dataWithContentsOfURL:[NSURL
URLWithString:stringPath]];
NSString *str = [[NSString alloc]initWithData:drfData
encoding:NSUTF8StringEncoding];
Works great, even if I use cyrillic words ("ïðèâåò").
Now, I use following code to add each word as object to my NSMutableArray.
To detect what is a word, I separated them by comma in my testFile.txt
document.
int nLastPoint = 0;
int nCount = 0;
for (int i = 0; i< str.length; i++) {
if ([[str substringWithRange:NSMakeRange(i,
1)]isEqualToString:@","]) {
[lst_wordlist addObject:[[[str
substringWithRange:NSMakeRange(nLastPoint, nCount)]
stringByTrimmingCharactersInSet:[NSCharacterSet
whitespaceAndNewlineCharacterSet]] uppercaseString]];
nLastPoint = i+1;
nCount = 0;
}else{
nCount++;
}
}
int nLength = 0;
for (int i = 0; i< [lst_wordlist count]; i++) {
if ([[lst_wordlist objectAtIndex:i]length]>nLength) {
nLength = [[lst_wordlist objectAtIndex:i]length];
}
}
NSLog(@"%@",lst_wordlist);
Works great, again ONLY if I use english words. With Cyrillic words
doesn't work.
This is my NSLog when I use a cyrillic word.
"\U041f\U0420\U0418\U0412\U0415\U0422",
WORD2,
WORD3,
Any ideas? How can I fix it? I tried to change debugger from LLDB to GDB,
doesn't fix the problem.

No comments:

Post a Comment