To correctly display UTF-8 text in a WebView
, I usually use a doctype
and a meta
tag :
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
and I use a tip I've seen on Stack Overflow:
string = URLEncoder.encode(string, "UTF-8").replaceAll("\\+", " ");
That works fine on Gingerbread and older Android versions, but my Nexus S recently received the Ice Cream Sandwich update, and French characters like é
, à
, è
, etc. are displayed like this: é
, for example.
I don't know if the ISO-xxxx-1 encoding is the solution, but if someone had the same problem, please share.
Windows-1252 is a subset of UTF-8 in terms of 'what characters are available', but not in terms of their byte-by-byte representation. Windows-1252 has characters between bytes 127 and 255 that UTF-8 has a different encoding for. Any visible character in the ASCII range (127 and below) are encoded 1:1 in UTF-8.
The main difference between UTF-8, UTF-16, and UTF-32 character encoding is how many bytes it requires to represent a character in memory. UTF-8 uses a minimum of one byte, while UTF-16 uses a minimum of 2 bytes.
UTF-8 is the dominant encoding for the World Wide Web (and internet technologies), accounting for 98.0% of all web pages, and up to 100.0% for many languages, as of 2022.
UTF-8 is backward-compatible with ASCII and can represent any standard Unicode character. The first 128 UTF-8 characters precisely match the first 128 ASCII characters (numbered 0-127), meaning that existing ASCII text is already valid UTF-8. All other characters use two to four bytes.
Try using the method loadDataWithBaseURL with random String for the other params instead of loadData
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With