How To Display Accented Characters Using Nsmutableattributedstring?
Solution 1:
You don't need to know the encoding of your NSString
– it is an Objective-C string. The definition of dataUsingEncoding:
states, emphasis added:
Returns an
NSData
object containing a representation of the receiver encoded using a given encoding.
This method converts from whatever encoding NSString
uses internally into the specified encoding – so the result is your case is an NSData
containing the bytes of a UTF8 string.
If you are seeing invalid results maybe the issue is when you create the original NSString
?
HTH
Addendum I now see you asked this question first (I added an answer – basically you need to know or guess). Why are you reading the file into an NSString
in the first place? Just read it directly into an NSData
and then let the HTML parser sort it out (it will either read the HTML encoding tag or default to an encoding).
Solution 2:
Eventually, I found that if I use NSUnicodeStringEncoding
on the above, the accented chars will be displayed correctly.
Post a Comment for "How To Display Accented Characters Using Nsmutableattributedstring?"