Jump to content
  • Advertisement
Sign in to follow this  
Horatius83

[java] Unicode Question

This topic is 4782 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!