How can I convert Plain Text (.txt) files to a string if the encoding type is unknown?
I\'m working on a feature that would allow users to import txt files into my a
Sometimes stringWithContentsOfFile:usedEncoding:error:
can do the job (esp if the file has a Byte Order Mark):
NSError *error;
NSStringEncoding encoding;
NSString *string = [NSString stringWithContentsOfFile:path usedEncoding:&encoding error:&error];
Note, this rendition with usedEncoding
should not be confused with the similarly named method that just has a encoding
parameter.