Bakhtiyor
Bakhtiyor

Reputation: 7318

A string get from TextField is not possible to convert into lowercase in J2ME

I have a TextField and I would like to get its content and convert it into a lowercase string. Here is my code:

TextField searchWord = new TextField("label", "Some Text", 35, TextField.ANY);
String word = searchWord.getString();
String word2 = word.toLowerCase();
System.out.println(word2);

If I enter a word "Book" into a textbox it works fine, i.e. word2 will be a string "book", but if I enter a russian word "Книга" it doesn't work at all, i.e. word2 is still "Книга".

Is there any hacking for such kind of situations?

Thank you

Upvotes: 0

Views: 517

Answers (2)

Stephen C
Stephen C

Reputation: 719259

I think that the answer is: "It doesn't work on J2ME!"

Reference: Convert char to lower case in J2ME without using the Character class ... which asks for a work-around.

I don't know the reason why it doesn't work (and I can't access the J2ME source code to find out!), but I suspect the reason is that the implementation of Character.toLower() on your Java ME platform only works for ASCII.

I note that while the Java SE javadocs for these methods say that they follow what the Unicode standard says, the Java ME javadocs are simply vague. This leaves it up to Java ME platform implementers to decide what to do, and in your case they appear to have botched it.

Opinion: this is the kind of nonsense that causes people to say that Sun / Oracle have mismanaged J2ME.

Upvotes: 0

npinti
npinti

Reputation: 52185

I think you need to use the toLowerCase(Locale loc) method:

Converts all of the characters in this String to lower case using the rules of the given Locale.

Here is a list of locales which are available in the Java SE 7 Platform.

Upvotes: 2

Related Questions