Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

How can see a string's unicode?

Thread view: 
au.danji@gmail.com - 14 Nov 2007 19:55 GMT
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!
RedGrittyBrick - 14 Nov 2007 21:39 GMT
> Hello, if I have a string A, how I can see the string's unicode?  say,
> display the String with format: "\u611F\u5192";
[quoted text clipped - 6 lines]
> 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
Roedy Green - 15 Nov 2007 23:43 GMT
On Wed, 14 Nov 2007 19:55:06 -0000, "au.danji@gmail.com"
<au.danji@gmail.com> wrote, quoted or indirectly quoted someone who
said :

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

What you are asking in how to convert a String to char[].  From there
you want to dump each char in hex, and prefix a decorative \u

See http://mindprod.com/jgloss/conversion.html
http://mindprod.com/jgloss/hex.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

John O'Conner - 16 Nov 2007 05:58 GMT
> 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
Arne Vajhøj - 17 Nov 2007 17:29 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.