List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:corner.orm.tapestry.service.captcha.RandomUtil.java
/** * ???// w w w.jav a 2 s . c o m * @param string * @return ? */ public static String encodeStr(String string) { String str = DigestUtils.md5Hex(string); StringBuffer sb = new StringBuffer(); sb.append(str.charAt(7)); sb.append(str.charAt(15)); sb.append(str.charAt(23)); sb.append(str.charAt(31)); return sb.toString(); }
From source file:Main.java
public static boolean isFirstUpperCase(String target) throws NullPointerException { if (target == null) throw new NullPointerException(); final char c = target.charAt(0); for (int i = 0, size = UpperCases.length; i < size; i++) { if (UpperCases[i] == c) { return true; }//from www . jav a 2 s. c om } return false; }
From source file:Main.java
public static int skipLeadingAsciiWhitespace(String input, int pos, int limit) { for (int i = pos; i < limit; i++) { switch (input.charAt(i)) { case '\t': case '\n': case '\f': case '\r': case ' ': continue; default:/*w ww . j a v a2 s . c om*/ return i; } } return limit; }
From source file:Main.java
public static int ELFHash(String str) { int hash = 0; int x = 0;/*from w w w. j a v a 2 s . c om*/ for (int i = 0; i < str.length(); i++) { hash = (hash << 4) + str.charAt(i); if ((x = (int) (hash & 0xF0000000L)) != 0) { hash ^= (x >> 24); hash &= ~x; } } return (hash & 0x7FFFFFFF); }
From source file:Main.java
public static String getShadowStyleVersionNumber(String peer_id) { String ver_number = decodeAlphaNumericChar(peer_id.charAt(1)); if (ver_number == null) { return null; }// w ww . j a v a 2s. c om for (int i = 2; i < 6 && ver_number != null; i++) { char c = peer_id.charAt(i); if (c == '-') { break; } ver_number = joinAsDotted(ver_number, decodeAlphaNumericChar(peer_id.charAt(i))); if (ver_number == null) { return (null); } } // We'll strip off trailing redundant zeroes. while (ver_number.endsWith(".0")) { ver_number = ver_number.substring(0, ver_number.length() - 2); } return ver_number; }
From source file:Main.java
/** * Return PITarget from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions <code>[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'</code> */// w w w . j a v a 2 s .c o m public static String getPITarget(final XmlPullParser pp) throws IllegalStateException { int eventType; try { eventType = pp.getEventType(); } catch (final XmlPullParserException x) { // should never happen ... throw new IllegalStateException("could not determine parser state: " + x + pp.getPositionDescription()); } if (eventType != XmlPullParser.PROCESSING_INSTRUCTION) throw new IllegalStateException("parser must be on processing instruction and not " + XmlPullParser.TYPES[eventType] + pp.getPositionDescription()); final String PI = pp.getText(); for (int i = 0; i < PI.length(); i++) { if (isS(PI.charAt(i))) { // assert i > 0 return PI.substring(0, i); } } return PI; }
From source file:Main.java
public static String formatPhone(String number) { StringBuffer sb = new StringBuffer(); char c;//w w w.ja v a 2 s. c om for (int i = 0; i < number.length(); i++) { c = number.charAt(i); if (48 <= c && c <= 57) sb.append(c); } return sb.toString(); }
From source file:Main.java
public static String removeDoubleQuotes(String string) { if (TextUtils.isEmpty(string)) return ""; int length = string.length(); if ((length > 1) && (string.charAt(0) == '"') && (string.charAt(length - 1) == '"')) { return string.substring(1, length - 1); }/*from w w w . ja v a 2 s . co m*/ return string; }
From source file:Main.java
public static String compact(String s) { char[] cs = new char[s.length()]; int len = 0;/*from ww w .j a v a2 s .c o m*/ for (int n = 0; n < cs.length; n++) { char c = s.charAt(n); if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == CHAR_CHINESE_SPACE) continue; cs[len] = c; len++; } return new String(cs, 0, len); }
From source file:Main.java
private static void appendAttributeValue(StringBuilder builder, String value) { int n = value.length(); for (int i = 0; i < n; i++) { char c = value.charAt(i); switch (c) { case '<': builder.append("<"); break; case '>': builder.append(">"); break; case '&': builder.append("&"); break; default://from w w w .j a va 2 s . c o m builder.append(c); break; } } }