List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:Main.java
public static String toUpperString(String s) { int idx = 0;/*from w w w . j a va2 s.co m*/ for (; idx < s.length(); idx++) { char c = s.charAt(idx); if (c >= 'a' && c <= 'z') { break; } } if (idx == s.length()) { return s; } StringBuilder buf = new StringBuilder(s.substring(0, idx)); for (; idx < s.length(); idx++) { buf.append(toUpper(s.charAt(idx))); } return buf.toString(); }
From source file:Main.java
private static String substring(String s, int beginIndex, int endIndex) { while (beginIndex < endIndex && s.charAt(beginIndex) <= ' ') beginIndex++;//from ww w .jav a 2s. co m while (beginIndex < endIndex && s.charAt(endIndex - 1) <= ' ') endIndex--; return beginIndex < endIndex ? s.substring(beginIndex, endIndex) : ""; }
From source file:Main.java
public static Integer[] getDigits(String number) { List<Integer> digits = new ArrayList<Integer>(); for (int i = 0; i < number.length(); i++) { int j = Character.digit(number.charAt(i), 10); digits.add(j);//from w w w . ja v a 2 s .co m } return digits.toArray(new Integer[] {}); }
From source file:Main.java
public static int oneByOneHash(String key) { int hash, i;/*from w w w.j a v a2 s.c o m*/ for (hash = 0, i = 0; i < key.length(); ++i) { hash += key.charAt(i); hash += (hash << 10); hash ^= (hash >> 6); } hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); // return (hash & M_MASK); return hash; }
From source file:Main.java
public static byte[] UdpHexDecode(String s) { byte abyte0[] = new byte[s.length() / 2]; String s1 = s.toLowerCase(); for (int i = 0; i < s1.length(); i += 2) { char c = s1.charAt(i); char c1 = s1.charAt(i + 1); int j = i / 2; if (c < 'a') abyte0[j] = (byte) (c - 48 << 4); else/*from ww w.j a v a 2 s. c o m*/ abyte0[j] = (byte) ((c - 97) + 10 << 4); if (c1 < 'a') abyte0[j] += (byte) (c1 - 48); else abyte0[j] += (byte) ((c1 - 97) + 10); } return abyte0; }
From source file:Main.java
public static Boolean _isItReadable(String input) { int readableChar = 0; for (int i = 0; i < input.length(); i++) { int c = input.charAt(i); if (c >= 32 && c < 127) { readableChar++;/*w w w . j av a 2 s . c o m*/ } } return (readableChar > (input.length() * 0.75) ? true : false); }
From source file:Main.java
public static String toLowerString(String s) { int idx = 0;//from ww w . j a va 2s .co m for (; idx < s.length(); idx++) { char c = s.charAt(idx); if (c >= 'A' && c <= 'Z') { break; } } if (idx == s.length()) { return s; } StringBuilder buf = new StringBuilder(s.substring(0, idx)); for (; idx < s.length(); idx++) { buf.append(toLower(s.charAt(idx))); } return buf.toString(); }
From source file:Main.java
/** * Normalizes the phone number format./* w ww. j av a2 s. c o m*/ * * @param number the input phone number. * @return a normalized phone number. */ public static String normalizePhone(String number) { if (number != null && number.length() > 0) { if (number.charAt(0) == '+') { number = "+" + number.substring(1).replaceAll("[^\\d]", ""); return number; } else { number = number.replaceAll("[^\\d]", ""); if (number.length() == 10) return "+1" + number; else if (number.length() == 11 && number.charAt(0) == '1') return "+" + number; else if (number.length() > 10) return "+" + number; else return "+1" + number; } } else { return "+1"; } }
From source file:Main.java
public static boolean isQuotedString(String string) { if (TextUtils.isEmpty(string)) return false; if (string.length() >= 2 && string.charAt(0) == '"' && string.charAt(string.length() - 1) == '"') return true; return false; }
From source file:Main.java
public static boolean isLetterBegin(String s) { if (TextUtils.isEmpty(s)) return false; else {//w w w . j a v a2 s . c o m char c = s.charAt(0); int i = (int) c; if ((i >= 65 && i <= 90) || (i >= 97 && i <= 122)) { return true; } else { return false; } } }