I've tried all the string encoding but still cannot read a text file.
I've tried all the string encoding but still cannot read a text file.
- Subject: I've tried all the string encoding but still cannot read a text file.
- From: Allen Dang <email@hidden>
- Date: Fri, 25 Jan 2008 20:45:36 +0800
Hi,
I try to read content of a text file with encoding GB2312 (simplified
chinese encoding), I get the encoding information from one windows
software named "EmEditor".
I tried all the string encoding that cocoa provides but still cannot
read the content, what can I do now?
Following is related code:
int encoders[ENCODERSLENGTH] = {
30, //Western (Mac OS Roman)
-2147483647, //Japanese (Mac OS)
-2147483646, //Traditional Chinese (Mac OS)
-2147483645, //Korean (Mac OS)
-2147483644, //Arabic (Mac OS)
-2147483643, //Hebrew (Mac OS)
-2147483642, //Greek (Mac OS)
-2147483641, //Cyrillic (Mac OS)
-2147483639, //Devanagari (Mac OS)
-2147483638, //Gurmukhi (Mac OS)
-2147483637, //Gujarati (Mac OS)
-2147483627, //Thai (Mac OS)
-2147483623, //Simplified Chinese (Mac OS)
-2147483622, //Tibetan (Mac OS)
-2147483619, //Central European (Mac OS)
6, //Symbol (Mac OS)
....
};
int i = 0;
for (i; i < ENCODERSLENGTH; i++)
{
NSStringEncoding encoding = encoders[i];
NSError *error;
NSString *contentString = [NSString stringWithContentsOfFile:filePath
usedEncoding:&encoding
error:&error];
if (error != nil)
{
NSLog([error localizedDescription]);
}
if (contentString != nil)
{
[textView setString:contentString];
break;
}
}
Allen Dang
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden