Example usage for java.lang Character isLetterOrDigit

List of usage examples for java.lang Character isLetterOrDigit

Introduction

In this page you can find the example usage for java.lang Character isLetterOrDigit.

Prototype

public static boolean isLetterOrDigit(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a letter or digit.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    char symbol = 'A';

    if (Character.isLetterOrDigit(symbol)) {
        System.out.println("true");
    } else {/*  w  ww.java2 s.com*/
        System.out.println("false");
    }
}

From source file:Main.java

public static void main(String[] args) {
    char ch1 = 'A', ch2 = '1';

    boolean b1 = Character.isLetterOrDigit(ch1);
    boolean b2 = Character.isLetterOrDigit(ch2);

    System.out.println(b1);/*from www  .  j  av a2  s. com*/
    System.out.println(b2);
}

From source file:Main.java

public static void main(String[] args) {
    int cp1 = 0x0033, cp2 = 0x023;

    boolean b1 = Character.isLetterOrDigit(cp1);
    boolean b2 = Character.isLetterOrDigit(cp2);

    System.out.println(b1);//from   w  w  w. ja v  a2  s .  co  m
    System.out.println(b2);
}

From source file:Main.java

public static void main(String[] args) throws java.io.IOException {
    char c = 'a';

    System.out.println("Character = " + (int) c);
    System.out.println("Defined = " + Character.isDefined(c));
    System.out.println("Digit = " + Character.isDigit(c));
    System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
    System.out.println("ISO control = " + Character.isISOControl(c));
    System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
    System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
    System.out.println("Letter = " + Character.isLetter(c));
    System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
    System.out.println("Lowercase = " + Character.isLowerCase(c));
    System.out.println("Space = " + Character.isSpaceChar(c));
    System.out.println("Titlecase = " + Character.isTitleCase(c));
    System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
    System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
    System.out.println("Uppercase = " + Character.isUpperCase(c));
    System.out.println("White space = " + Character.isWhitespace(c));

    byte[] types = { Character.COMBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION, Character.CONTROL,
            Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION, Character.DECIMAL_DIGIT_NUMBER,
            Character.ENCLOSING_MARK, Character.END_PUNCTUATION, Character.FORMAT, Character.LETTER_NUMBER,
            Character.LINE_SEPARATOR, Character.LOWERCASE_LETTER, Character.MATH_SYMBOL,
            Character.MODIFIER_SYMBOL, Character.NON_SPACING_MARK, Character.OTHER_LETTER,
            Character.OTHER_NUMBER, Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL,
            Character.PARAGRAPH_SEPARATOR, Character.PRIVATE_USE, Character.SPACE_SEPARATOR,
            Character.START_PUNCTUATION, Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
            Character.UPPERCASE_LETTER };

    String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control", "Currency symbol",
            "Dash punctuation", "Decimal digit number", "Enclosing mark", "End punctuation", "Format",
            "Letter number", "Line separator", "Lowercase letter", "Math symbol", "Modifier symbol",
            "Non spacing mark", "Other letter", "Other number", "Other punctuation", "Other symbol",
            "Paragraph separator", "Private use", "Space separator", "Start punctuation", "Surrogate",
            "Titlecase letter", "Unassigned", "Uppercase letter" };

    int type = Character.getType(c);

    for (int i = 0; i < types.length; i++)
        if (type == types[i]) {
            System.out.println("Type name = " + typeNames[i]);
            break;
        }//from   ww w .  j  a v  a 2 s.com

    System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}

From source file:Classify.java

public static void main(String[] args) throws java.io.IOException {
    char c = '\u0beb'; // Tamil digit.

    System.out.println("Character = " + (int) c);
    System.out.println("Defined = " + Character.isDefined(c));
    System.out.println("Digit = " + Character.isDigit(c));
    System.out.println("Ignorable = " + Character.isIdentifierIgnorable(c));
    System.out.println("ISO control = " + Character.isISOControl(c));
    System.out.println("Java identifier part = " + Character.isJavaIdentifierPart(c));
    System.out.println("Java identifier start = " + Character.isJavaIdentifierStart(c));
    System.out.println("Letter = " + Character.isLetter(c));
    System.out.println("Letter or digit = " + Character.isLetterOrDigit(c));
    System.out.println("Lowercase = " + Character.isLowerCase(c));
    System.out.println("Space = " + Character.isSpaceChar(c));
    System.out.println("Titlecase = " + Character.isTitleCase(c));
    System.out.println("Unicode identifier part = " + Character.isUnicodeIdentifierPart(c));
    System.out.println("Unicode identifier start = " + Character.isUnicodeIdentifierStart(c));
    System.out.println("Uppercase = " + Character.isUpperCase(c));
    System.out.println("White space = " + Character.isWhitespace(c));

    byte[] types = { Character.COMBINING_SPACING_MARK, Character.CONNECTOR_PUNCTUATION, Character.CONTROL,
            Character.CURRENCY_SYMBOL, Character.DASH_PUNCTUATION, Character.DECIMAL_DIGIT_NUMBER,
            Character.ENCLOSING_MARK, Character.END_PUNCTUATION, Character.FORMAT, Character.LETTER_NUMBER,
            Character.LINE_SEPARATOR, Character.LOWERCASE_LETTER, Character.MATH_SYMBOL,
            Character.MODIFIER_SYMBOL, Character.NON_SPACING_MARK, Character.OTHER_LETTER,
            Character.OTHER_NUMBER, Character.OTHER_PUNCTUATION, Character.OTHER_SYMBOL,
            Character.PARAGRAPH_SEPARATOR, Character.PRIVATE_USE, Character.SPACE_SEPARATOR,
            Character.START_PUNCTUATION, Character.SURROGATE, Character.TITLECASE_LETTER, Character.UNASSIGNED,
            Character.UPPERCASE_LETTER };

    String[] typeNames = { "Combining spacing mark", "Connector punctuation", "Control", "Currency symbol",
            "Dash punctuation", "Decimal digit number", "Enclosing mark", "End punctuation", "Format",
            "Letter number", "Line separator", "Lowercase letter", "Math symbol", "Modifier symbol",
            "Non spacing mark", "Other letter", "Other number", "Other punctuation", "Other symbol",
            "Paragraph separator", "Private use", "Space separator", "Start punctuation", "Surrogate",
            "Titlecase letter", "Unassigned", "Uppercase letter" };

    int type = Character.getType(c);

    for (int i = 0; i < types.length; i++)
        if (type == types[i]) {
            System.out.println("Type name = " + typeNames[i]);
            break;
        }/*from www. ja  v a  2  s .c  o m*/

    System.out.println("Unicode block = " + Character.UnicodeBlock.of(c));
}

From source file:Main.java

private static String cleanupSearchString(String search) {
    if (search == null)
        return "";

    StringBuilder out = new StringBuilder(search.length());
    char prev = ' ';
    for (char curr : search.toCharArray()) {
        if (Character.isLetterOrDigit(curr)) {
            out.append(curr);/*  w w w  .  ja v a2  s. co m*/
        } else {
            curr = ' ';
            if (!Character.isWhitespace(prev)) {
                out.append(curr);
            }
        }
        prev = curr;
    }
    return out.toString();
}

From source file:Main.java

public static boolean isLegalName(String n) {
    if (n.length() == 0)
        return false;
    if (!Character.isLetter(n.charAt(0)))
        return false;
    for (int i = 0; i < n.length(); i++) {
        char c = n.charAt(i);
        if (Character.isLetterOrDigit(c))
            continue;
        if (c == '_')
            continue;
        if (c == '.')
            continue;
        return false;
    }//from   w ww.j  a v a 2 s.c  om
    if (n.length() > 1) {
        String n2 = n.substring(0, 2);
        if (n2.equalsIgnoreCase("JS"))
            return false;
    }
    if (n.indexOf("__") >= 0)
        return false;
    if (reservedWords.contains(n))
        return false;
    return true;
}

From source file:Main.java

static String removeJunk(String string) {
    int i, len = string.length();
    StringBuffer dest = new StringBuffer(len);
    char c;/*from w  w  w  .  j ava2 s .co m*/

    for (i = (len - 1); i >= 0; i--) {
        c = string.charAt(i);
        if (Character.isLetterOrDigit(c)) {
            dest.append(c);
        }
    }
    return dest.toString();
}

From source file:Main.java

static void extractWords(String target, BreakIterator wordIterator) {
    wordIterator.setText(target);//w w  w.  j  av  a2s.  c o m
    int start = wordIterator.first();
    int end = wordIterator.next();

    while (end != BreakIterator.DONE) {
        String word = target.substring(start, end);
        if (Character.isLetterOrDigit(word.charAt(0))) {
            System.out.println(word);
        }
        start = end;
        end = wordIterator.next();
    }
}

From source file:Main.java

/**
 * Converts a string to title casing.// w w  w . ja  v a  2s  . c om
 * @param str
 *      The string to convert.
 * @return
 *      The converted string.
 */
public static String toTitleCase(String str) {
    if (str == null) {
        return null;
    }
    // skip if already contains mixed case
    if (!str.equals(str.toLowerCase()) && !str.equals(str.toUpperCase())) {
        return str;
    }

    boolean isSeparator = true;
    StringBuilder builder = new StringBuilder(str);
    final int len = builder.length();

    for (int i = 0; i < len; ++i) {
        char c = builder.charAt(i);
        if (isSeparator) {
            if (Character.isLetterOrDigit(c)) {
                // Convert to title case and switch out of whitespace mode.
                builder.setCharAt(i, Character.toTitleCase(c));
                isSeparator = false;
            }
        } else if (!Character.isLetterOrDigit(c)) {
            isSeparator = true;
        } else {
            builder.setCharAt(i, Character.toLowerCase(c));
        }
    }

    return builder.toString();
}