Hi all!
How to convert unicode string to ascii string or byte array?
Hi all!
How to convert unicode string to ascii string or byte array?
It depends...
1) What Unicode encoding (UTF-8, UTF-16/UCS-2 or something else) is used for the Unicode string
2) What actual data (characters) is contained (anything other characters that are not corresponding to the ASCII values of 0-127 cannot be converted; or you have to replace them with some other character that exists in ASCII, and thus loosing data/information.
In the simplest conversion, you'd just discard every Unicode character, except those where the first byte is zero and the second byte has a value of 0-127. Anything where the first byte is more than 0, and the second byte is 128 or larger has no ASCII representation. You can also replace those with some other valid ASCII character.
Read this for an intro on Unicode and various encodings:
http://www.joelonsoftware.com/printe...s/Unicode.html
1)UTF-8 I think
2)My midlet's user enter a string using his own language. I must include this string in url. Somthing like this:
"host.com?name="+strUserName
As I told, strUserName can be any language.
Then you shouldn't convert the user-supplied entered string to ASCII, because you don't know whether that's doable or not.
Just use URL encoding and let the server/host handle it.
Here's a wiki article about that:
http://wiki.forum.nokia.com/index.ph...in_Java_ME_%3F
I have made some changes, and now this is what I realy need! Thanks a lot!
About changes I made: I add coding for slash symbol:
....
} else if(ch == '\\') {
sbuf.append("%5C");
}
.....