jacekmalinowski
asked on
How do i detect the encoding of a text file?
How do i detect the encoding of a text file?
Is there a way to automatically detect encoding of a file?
Is there a way to automatically detect encoding of a file?
NSString *txtFile = [NSString stringWithContentsOfFile:newFilePath
encoding: ??? I don't know encoding
error:nil];
ASKER
Thanks for your reply.
The problem is I have to know the text file encoding before it's read to NSString object.
The problem is I have to know the text file encoding before it's read to NSString object.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot!
NSString *txtFile = [NSString stringWithContentsOfFile:f ilePath usedEncoding:encodingOfFil e error:&error];
encodingOfFile returns encoding of the file.
NSString *txtFile = [NSString stringWithContentsOfFile:f
encodingOfFile returns encoding of the file.
Cool. :)
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/canBeConvertedToEncoding:
Here you will see how availableStringEncodings method is used:
http://www.cocoadev.com/index.pl?CharacterEncoding