How can see a string's unicode?

A

au.danji

Hello, if I have a string A, how I can see the string's unicode? say,
display the String with format: "\u611F\u5192";

Currently I have a string A, which I don't know the encoding, but if I
display that string in the firefox browser, it is just some strange
letters, like this "感å". Actually is should display some meaningful
chinese characters, like "感冒"。

Can any one tell me how to convert the string A into unicode format
and let it display correctly in the browser?

Thanks a lot!
 
R

RedGrittyBrick

Hello, if I have a string A, how I can see the string's unicode? say,
display the String with format: "\u611F\u5192";

Currently I have a string A, which I don't know the encoding, but if I
display that string in the firefox browser, it is just some strange
letters, like this "感å". Actually is should display some meaningful
chinese characters, like "感冒"。

Can any one tell me how to convert the string A into unicode format
and let it display correctly in the browser?

Just tell the browser it is UTF8

HTTP:
Content-Type: text/html; charset=utf-8

HTML:
<META http-equiv=Content-Type content="text/html; charset=UTF-8">

XHTML:
http://www.w3.org/TR/2002/NOTE-xhtml-media-types-20020430/#text-html
 
J

John O'Conner

Hello, if I have a string A, how I can see the string's unicode? say,
display the String with format: "\u611F\u5192";

Currently I have a string A, which I don't know the encoding,

If you mean a Java String, then the String A is in Unicode, represented
in the API as UTF-16 code units.

but if I
display that string in the firefox browser, it is just some strange
letters, like this "感å". Actually is should display some meaningful
chinese characters, like "感冒"。

Usually this is a combination of font choice and charset declaration.
Make sure you 1) declare the charset encoding of the HTML file and
generate the appropriate character code units for the HTML, and 2)have a
font that can contains glyphs for the Chinese characters.


Can any one tell me how to convert the string A into unicode format
and let it display correctly in the browser?


The String A is already a Unicode encoding -- UTF-16. Use the
String#getBytes method to get a byte[] in a different encoding.


Regards,
John O'Conner
 
A

Arne Vajhøj

Hello, if I have a string A, how I can see the string's unicode? say,
display the String with format: "\u611F\u5192";

public static String encode(String s) {
StringBuffer sb = new StringBuffer("");
for(int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if((c >= 0) && (c <=255)) {
sb.append(c);
} else {
String hex = Integer.toHexString(c);
sb.append("\\u" + "0000".substring(hex.length(), 4) + hex);
}
}
return sb.toString();
}

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,286
Latest member
ChristieSo

Latest Threads

Top