I am retrieving HTML, containing UTF8 or ASCII encoded text. For most common use it is ASCII decoding that works to display the text right:
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
Now I have another HTML page with UTF8 encoding, so I have to use:
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
What kind of encoding I retrieve is random when loading websites. My question is, is there a way to check the NSData for what kind of decoding is the right to use? So I know which encoding type I need to use.
Thnx!
I don't know if it is possible to check the encoding of NSData so this is what I did:
Although Heliem answer is useful, it is not a solution if ASCII and UTF8 give both a string in return. For instance: UTF8 gives me some extra characters (negative result) and ASCII are showing the right characters (positive result). I now use the following code: