Android Utililty Methods String Char Get

List of utility methods to do String Char Get

Description

The list of methods to do String Char Get are organized into topic(s).

Method

charcharAt(String str, int index)
char At
return str.charAt(index >= 0 ? index : str.length() + index);
StringcharSubString(String str, int charLen)
char Sub String
StringBuffer sb = new StringBuffer();
int counter = 0;
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    sb.append(c);
    if (c < 255) {
        counter++;
    } else {
...
intgetCharLength(String str)
get Char Length
int counter = 0;
for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    if (c < 255) {
        counter++;
    } else {
        counter = counter + 2;
return counter;
intgetCharNum(String str, char ch)
get Char Num
int num = 0;
for (int i = 0; i < str.length(); ++i) {
    if (str.charAt(i) - ch == 0) {
        num++;
return num;
chargetFirstChar(String ch)
get First Char
if (!isChinese(ch)) {
    char[] charArray = ch.toCharArray();
    if (charArray.length > 0) {
        return charArray[0];
    } else {
        return 0;
byte[] bytes = new byte[2];
try {
    bytes = ch.getBytes("GB2312");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
char result = '-';
int secPosValue = 0;
int i;
for (i = 0; i < bytes.length; i++) {
    bytes[i] -= GB_SP_DIFF;
secPosValue = bytes[0] * 100 + bytes[1];
for (i = 0; i < 23; i++) {
    if (secPosValue >= secPosValueList[i]
            && secPosValue < secPosValueList[i + 1]) {
        result = firstLetter[i];
        break;
return result;
booleanisValidChar(String strInput)
is Valid Char
String strPattern = "^[0-9a-zA-Z]*$";
Pattern p = Pattern.compile(strPattern);
Matcher m = p.matcher(strInput);
return m.matches();
booleanisAllCharDigit(String str)
is All Char Digit
int length = str.length();
if (length == 0) {
    return false;
for (int i = 0; i < length; i++) {
    if (!Character.isDigit(str.charAt(i))) {
        return false;
return true;
booleanisAllWhitespace(CharSequence str)
is All Whitespace
for (int i = 0; i < str.length(); i++) {
    if (!Character.isWhitespace(str.charAt(i))) {
        return false;
return true;