![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2006
Posts: 1
Rep Power: 0
![]() |
Unicode Problems
Hi there!
I am running into a bit of a problem with Unicode. I am trying to make a game that will work in many languages, English, Greek, Japanese, Chinese etc. So far so good. I have created a class that converts a String into unicode characters. For instance String s = stringToUnicode("lie"); s=="\u0077\u0061\u0074"; I have also created a method that does the opposite. So if I say String s = unicodeToString("\u0077\u0061\u0074"); then s == "lie"; However when I am trying to read the string "\u0077\u0061\u0074" from an XML (UTF-8) file, then there's no way on earth to convert it into a character. For some inexplicable reason it returns as a string and the escape \u characters cannot be dereferenced. For example \u0077 cannot be expressed as 1 character (char c = '\u0077') but it is returned as a string String s = "\u0077" and I have tried so many things but it seems impossible to make a character again!! ![]() Any help please? Ideally I am looking to convert this string "\u0077\u0061\u0074" into a string of actual characters. It works if I do it in a Java class, but it doesn't work if this string is returned from a file. Thank you |
|
|
|
|
|
#2 | |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 769
Rep Power: 3
![]() |
What's wrong with just using Strings normally?
Quote:
|
|
|
|
|
|
|
#3 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,107
Rep Power: 5
![]() |
Quote:
First, you can use Unicode text files. This should allow you to read them from your Java programs just fine. Second, you can rewrite your function to convert a sequence of bytes (not chars) into a Java String. This way, you can read it from the file if it is ASCII (but if the file is Unicode, you've got problems unless you employ some logic to check for this somehow). Note I say ASCII here instead of UTF-8; the latter is a more complex format where characters range from one to four bytes (more details here).
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|