• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: I've tried all the string encoding but still cannot read a text file.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I've tried all the string encoding but still cannot read a text file.


  • Subject: Re: I've tried all the string encoding but still cannot read a text file.
  • From: Horst Hösel <email@hidden>
  • Date: Fri, 25 Jan 2008 14:20:35 +0100

Am 25.01.2008 um 13:45 schrieb Allen Dang:


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)
[snip]
-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;
}
}


[snip]


Allen,

You might want to try:

NSString *contentString = [NSString stringWithContentsOfFile:filePath
usedEncoding:CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingGB_2312_80)
error:&error];


HTH,
Horst

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >I've tried all the string encoding but still cannot read a text file. (From: Allen Dang <email@hidden>)

  • Prev by Date: Regular expressions in Cocoa?
  • Next by Date: Re: I've tried all the string encoding but still cannot read a text file.
  • Previous by thread: I've tried all the string encoding but still cannot read a text file.
  • Next by thread: Re: I've tried all the string encoding but still cannot read a text file.
  • Index(es):
    • Date
    • Thread