how to check for a Letter in J2ME from a char
IN J2SE we can use Character.isLetter(c)
I want to use this :
if (Character.isLetter(c) && Character.isUpperCase(c)){}
and also else if(Character.isSpace(c))
IN JAVA MOBILE Platform Any way to use it??
We can check whether the given character in a string is a number/letter by using isDigit() method of Character class. The isDigit() method is a static method and determines if the specified character is a digit.
You are looking for String. indexOf : int pos = activeWord. indexOf(letter); if (pos == -1) { // letter not found } else { // letter exists at zero-based position pos // CAUTION: it might also exist in later positions! }
You can search for a particular letter in a string using the indexOf() method of the String class. This method which returns a position index of a word within the string if found. Otherwise it returns -1.
The isLetter(char ch) method returns a Boolean value i.e. true if the given(or specified) character is a letter. Otherwise, the method returns false.
Seeing as you can't use Character.isLetter(c)
, I would just emulate its functionally. I would do this by treating the character as a "number" by using its ASCII value.
public static boolean isLetter(char c) {
return (c > 64 && c < 91) || (c > 96 && c < 123);
}
//Not necessary but included anyways
public static boolean isUpperCase(char c) {
return c > 64 && c < 91;
}
public static boolean isSpace(char c) {
//Accounts for spaces and other "space-like" characters
return c == 32 || c == 12 || c == 13 || c == 14;
}
Edit: Thank you @Nate for the suggestions/corrections
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With