views:

82

answers:

2

I'd like to convert a char to lower case in a J2ME app. The usual Character.toLowerCase() doesn't work for an arbitrary Unicode character in J2ME, so I need some light API, or, preferably, a piece of code that would do so.

Thanks!

A: 
char toLowerCase(char c){
    if(c>=97 && c<=122)
        return (char) (c-32);
    else
        return c;
}
keshav.veerapaneni
Simply brilliant.
SidCool
Perfect. But please tell me how in the world it is suppose to work with non-ASCII characters (like Ą, Ć, Ę, Ó, Ś... Not to mention Greek or Cyrillic)?
Paweł Dyda
-1 the question is about unicode, your answer only deals with ascii.
josefx
Unicode needed.
Albus Dumbledore
-1: not unicode compatible
Michael Konietzka
+2  A: 

Based on the toLowerCase() method from Character in JavaSE JDK:

char lowerChar = (char)CharacterData.of((int)upperChar).toLowerCase((int)upperChar);

You can read the source code from the JDK and understand what is really done here and apply the same thing with your own classes in JME.


Resources :

Colin Hebert
This answers the question title, but not the question message.
BalusC
@BalusC, I know it won't work as is in JME, I'm just saying that the best way to do this, is to look at the way this works with JSE. (Edited to make it more clear)
Colin Hebert
OK, my bad. I'll change the title. Of course, there is the possibility of porting some of the classes to j2me. It might be easier if their is nothing else.
Albus Dumbledore