Sign in to follow this  

[java] Unicode Question

This topic is 4595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want a program that can accept Unicode characters as input and output them to the screen, I had heard that Java supported double-byte characters by default (which is why I am attempting to port this project to Java from C++) but I have found only vague references to it in tutorials and books. Like say I try to create a string with Unicode characters in the constructor: String abs = new String("おほようございます","ISO8859_1"); This should work shouldn't it? But it doesn't, instead of おほようございます I'm getting a series of squares and the compiler flags it as an error. Is the problem with NetBeans IDE 3.6 or is it the language itself?

Share this post


Link to post
Share on other sites
Hi,

I usually do the following in networking code:



URLEncoder.encode(new String("international string", "iso-8859-1"), "iso-8859-1");



Which is, of course, bad programming, but it works just fine. I had several similar problems with character encoding, and I have searched a lot for a good tutorial that could clear my doubts, but with no success at all.

Son Of Cain

Share this post


Link to post
Share on other sites
You cannot type the literal characters into your source file and have them work; Java does support the data natively with its data types and classes (char, java.lang.String etc.), but the source file is expected to be encoded in Latin-1.

To represent those characters, escape them with \u#### (four hex digits) sequences.

Share this post


Link to post
Share on other sites

This topic is 4595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this