Link to home
Start Free TrialLog in
Avatar of jacekmalinowski
jacekmalinowskiFlag for Poland

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?
NSString *txtFile = [NSString stringWithContentsOfFile:newFilePath
encoding: ??? I don't know encoding
error:nil];

Open in new window

Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Avatar of jacekmalinowski

ASKER

Thanks for your reply.

The problem is I have to know the text file encoding before it's read to NSString object.
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot!
NSString *txtFile = [NSString stringWithContentsOfFile:filePath usedEncoding:encodingOfFile error:&error];

encodingOfFile returns encoding of the file.
Cool. :)