0

I'm lithuanian and I'm creating app in lithuanian language, but Strings can't contain letters such as: ą, č, ę, ė, į, š, ų, ū, ž...

I searched over the internet for simple way to make it possible, but I ended up there...

There is some of my code that I want to modify:

if (dayOfWeek.equals("Wednesday")) {
    dayOfWeek = "Treciadienis"; //this should be Trečiadienis
}

And I have Array that has bunch of these letters. How should I deal with it?

static JSONArray jArray = new JSONArray(data);

Thank you in advance!

1
  • you could use i18n, place all string you need in xml. Are they predefined or you getting text from web also? Commented Dec 7, 2013 at 20:02

3 Answers 3

0

A string can contain the letter ą. The following code dayOfWeek = "Treciadienis";.

  1. Do you have checked if your file is encoded in UTF-8 ? For that under Eclipse, do File => Properties, and you'll see in the bottom the Text file encoding.

  2. If you really can not, I think your talking about a a with ogonek, the other solution is to refer on bytes value of the String, and to do : dayOfWeek = "Tre".concat(new String(new byte[]{(byte) 0xC4})).concat("iadienis"); (yep, quite extreme, but it works).

Sign up to request clarification or add additional context in comments.

1 Comment

It worked with the first one! Thank you! I was scared when I Read second one.
0

It's very common if your're using Windows that Eclipse sets the default encoding to Cp1252, which you must change to UTF-8 so you're able to use that kind of characters hardcoded in your .java files. Don't forget that you can also use the string constructor:

String(byte[] data, String charsetName)

Comments

0

Adding Tod gahfy's answer:

Instead of adding individual bytes you can use the \uxxxx syntax within the String. Xxxx is the Unicode code point of the character. This is of course more annoying than using UTF-8 encoding but less annoying than adding bytes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.