Example usage for java.lang CharSequence charAt

List of usage examples for java.lang CharSequence charAt

Introduction

In this page you can find the example usage for java.lang CharSequence charAt.

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:Main.java

public static CharSequence trimTrailingWhitespace(CharSequence text) {
    while (text.charAt(text.length() - 1) == '\n') {
        text = text.subSequence(0, text.length() - 1);
    }/*  ww w.j ava2  s  .c om*/

    return text;
}

From source file:Main.java

public static boolean lastCharIsOperator(CharSequence text) {
    char last_char = text.charAt(text.length() - 1);
    return (last_char == '-' || last_char == '*' || last_char == '/' || last_char == '+');
}

From source file:Main.java

/**
 * Checks whether or not a phone number is a private caller or not.
 *//*w  ww .j  a  va 2  s  .co  m*/
public static boolean isPrivateCaller(CharSequence charsequence) {
    return TextUtils.isEmpty(charsequence) || '-' == charsequence.charAt(0);
}

From source file:Main.java

private static String getAppropriateEncoding(CharSequence contents) {
    for (int i = 0; i < contents.length(); i++) {
        if (contents.charAt(i) > 0xFF) {
            return "UTF-8";
        }//  w ww  . j av a2s.  co m
    }
    return null;
}

From source file:Main.java

private static int getEndIndex(CharSequence input) {
    int index = input.length() - 1;
    while (Character.isWhitespace(input.charAt(index))) {
        --index;/*w  w w . j  a  v  a2  s  . c  o  m*/
        if (index < 0) {
            break;
        }
    }
    return index;
}

From source file:Main.java

private static char getShortyType(CharSequence type) {
    if (type.length() > 1) {
        return 'L';
    }/*from   w  w w . j  a v  a2 s. c  o m*/
    return type.charAt(0);
}

From source file:Main.java

/**
 * Convert the hex string to the integer value.
 * @param str// w ww.  j  ava  2  s  . com
 * @return the integer value for the specified hex string
 */
public static int intFromHexString(CharSequence str) {
    int n = 0;
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        int v = c <= '9' ? c - '0' : c - 'a' + 10;
        n <<= 4;
        n |= (v & 0x0f);
    }
    return n;
}

From source file:Main.java

private static int getStartIndex(CharSequence input) {
    int length = input.length();
    int index = 0;
    while (Character.isWhitespace(input.charAt(index))) {
        ++index;//from   ww  w  . ja va  2s  .com
        if (index >= length) {
            break;
        }
    }
    return index;
}

From source file:Main.java

private static boolean isUpperCase(CharSequence sequence) {
    for (int i = 0; i < sequence.length(); i++) {
        if (Character.isLowerCase(sequence.charAt(i)))
            return false;
    }//ww  w .ja  v  a 2 s .  c  o m

    return true;
}

From source file:Main.java

private static String guessAppropriateEncoding(CharSequence contents) {
    // Very crude at the moment
    for (int i = 0; i < contents.length(); i++) {
        if (contents.charAt(i) > 0xFF) {
            return "UTF-8";
        }/*from   w w w.  ja va 2  s  .  c  o m*/
    }
    return null;
}