List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:Main.java
public static int stringToInteger(String inString, int inStart) { int result = 0; char letter = inString.charAt(inStart); boolean negate = false; if (letter == '-') { inStart += 1;/* www . ja va2 s .c om*/ negate = true; } else if (letter == '+') { inStart += 1; } result = stringToUnsigned(inString, inStart); return negate ? -result : result; }
From source file:Main.java
public static String convertPhoneNumberTo8Format(String text) { try {//from w w w. ja v a 2 s .c om text = text.trim(); if (text.charAt(0) == '+') { text = text.substring(1); } if (text.charAt(0) == '7') { StringBuilder strBuilder = new StringBuilder(text); strBuilder.setCharAt(0, '8'); text = strBuilder.toString(); } BigInteger dummy = new BigInteger(text); if (text.charAt(0) != '8' || text.length() != 11) { throw new Exception(); } } catch (Throwable t) { text = ""; //LOGE("convertPhoneNumberTo8Format: " + t.getMessage()); t.printStackTrace(); } return text; }
From source file:Main.java
protected static boolean validType(String str) { for (int count = 0; count < str.length(); count++) { char ch = str.charAt(count); if (validStr.indexOf(ch) == -1) { return false; }//www .j av a2 s . c o m } return true; }
From source file:Main.java
public static Color readColorAttr(Element element, String attributeName, Color defaultValue) { String s = element.getAttribute(attributeName); if (s == null || s.charAt(0) != '#') { return defaultValue; }// w ww . j a va 2 s. c o m try { return new Color(Integer.parseInt(s.substring(1), 16), false); } catch (NumberFormatException e) { e.printStackTrace(); return defaultValue; } }
From source file:Main.java
public static String randomString(int len, String charset) { String out = ""; for (int i = 0; i < len; i++) { out += charset.charAt((int) (Math.random() * charset.length())); }/* ww w . j a va2s .c om*/ return out; }
From source file:Main.java
/** * right trime character//from ww w. j av a2 s . c om * @param p_str * @param p_match trim out this pattern * @return */ public static String rtrim(String p_str, char p_match) { int i = p_str.length(); for (; i > 0; i--) if (p_str.charAt(i - 1) != p_match) break; return p_str.substring(0, i); }
From source file:Main.java
/** * Replaces instances of Emoji unicode characters with their Emoji-Cheat sheet key * * @param s/*from ww w . j a v a 2s .c om*/ * @return */ public static String replaceUnicodeEmojis(String s) { if (TextUtils.isEmpty(s)) { return ""; } for (int i = 0; i < s.length(); i++) { String key = s.substring(i, i + 1); if ((Character.isLowSurrogate(key.charAt(0)) || Character.isHighSurrogate(key.charAt(0))) && s.length() > i + 1) { key = s.substring(i, i + 2); } String emoji = UNICODE_TO_CHEAT_SHEET.get(key); if (null != emoji) { s = s.replace(key, emoji); } } return s; }
From source file:Main.java
public static String toHexString(String s) { String str = ""; for (int i = 0; i < s.length(); ++i) { char ch = s.charAt(i); String s4 = Integer.toHexString(ch); str = str + s4;//from w w w . j a va2 s.c o m } return str; }
From source file:Main.java
public static String validateAndFixUserPhoneNumber(String text) { try {/*from ww w .j a v a 2 s .com*/ text = text.trim(); if (text.charAt(0) == '+') { text = text.substring(1); } BigInteger dummy = new BigInteger(text); if (text.charAt(0) == '8') { StringBuilder strBuilder = new StringBuilder(text); strBuilder.setCharAt(0, '7'); text = strBuilder.toString(); } if (text.charAt(0) != '7' || text.length() != 11) { throw new Exception(); } text = "+" + text; } catch (Throwable t) { text = ""; //LOGE("validateAndFixUserPhoneNumber: " + t.getMessage()); t.printStackTrace(); } return text; }
From source file:Main.java
public static String toHexString(String s) { String str = ""; for (int i = 0; i < s.length(); i++) { int ch = (int) s.charAt(i); String s4 = Integer.toHexString(ch); str = str + s4;//from www.ja v a2s. c o m } return str; }