Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check for a Letter in J2ME from a char

Tags:

java

java-me

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??

like image 232
ChamathPali Avatar asked Feb 02 '13 17:02

ChamathPali


People also ask

How do you see if a char is a letter?

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.

How do you test if a letter is in a word?

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! }

How do you see if a letter is in a word Java?

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.

Is Java a letter?

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.


1 Answers

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

like image 53
supersam654 Avatar answered Oct 04 '22 00:10

supersam654