List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:Main.java
public static String getHexString(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')) { sb.append(c);/*from www .java 2s . c o m*/ } } if ((sb.length() % 2) != 0) { sb.deleteCharAt(sb.length()); } return sb.toString(); }
From source file:Main.java
/** * Returns the index of the first char of {@code chars} in {@code string} * bounded between {@code start} and {@code end}. This returns {@code end} * if none of the characters exist in the requested range. *///from ww w .j a va 2s . com public static int findFirstOf(String string, String chars, int start, int end) { for (int i = start; i < end; i++) { char c = string.charAt(i); if (chars.indexOf(c) != -1) { return i; } } return end; }
From source file:Main.java
public static boolean isToken(String tail) { if (tail == null || tail.length() == 0) return false; boolean result = isAlphabetic(tail.charAt(0)); for (int i = 1; i < tail.length(); i++) { result = result && (isAlphabetic(tail.charAt(i)) || isDigit(tail.charAt(i)) || (tail.charAt(i) == '_') || (tail.charAt(i) == '[') || (tail.charAt(i) == ']')); }//w w w. j a v a2s . c o m return result; }
From source file:Main.java
/** * "Flattens" a phone number into a standard format by eliminating all symbols, etc. *///from w w w . j a va 2 s . c o m public static String flattenPhone(String formattedPhone) { String flattened = PhoneNumberUtils.stripSeparators(formattedPhone); flattened = flattened.replaceAll("\\+", ""); if (flattened.charAt(0) == '1') flattened = flattened.replaceFirst("1", ""); return flattened; }
From source file:Main.java
public static boolean isLegalName(String n) { if (n.length() == 0) return false; if (!Character.isLetter(n.charAt(0))) return false; for (int i = 0; i < n.length(); i++) { char c = n.charAt(i); if (Character.isLetterOrDigit(c)) continue; if (c == '_') continue; if (c == '.') continue; return false; }//from w w w .j a v a 2 s . co m if (n.length() > 1) { String n2 = n.substring(0, 2); if (n2.equalsIgnoreCase("JS")) return false; } if (n.indexOf("__") >= 0) return false; if (reservedWords.contains(n)) return false; return true; }
From source file:Main.java
public static int retiraId(String nome) { int id = -1;//from w w w . jav a 2 s . c o m String idTemp = ""; for (int i = 0; i < nome.length(); i++) { if (nome.charAt(i) == '-') { break; } idTemp += nome.charAt(i); } id = Integer.parseInt(idTemp); return id; }
From source file:Main.java
public static String xmlEncode(String str) { String ret = ""; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c >= 128 || c < 32) { ret += "&#" + (int) c + ";"; } else/* w ww. ja v a 2 s .c o m*/ ret += c; } return ret; }
From source file:Main.java
/** * Remove zero characters from string value passed to method * @param s = string value to remove zeros from * @return s with zero's removed// w ww . j a v a 2 s . co m */ public static String removeZeros(String s) { String r = ""; char zero = '0'; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != zero) r += s.charAt(i); } return r; }
From source file:Main.java
private static String generateString(Random rng, String characters, int length) { char[] text = new char[length]; for (int i = 0; i < length; i++) { text[i] = characters.charAt(rng.nextInt(characters.length())); }//from w w w . j a v a 2s .c o m return new String(text); }
From source file:MainClass.java
public static String capitalize(String s) throws NullPointerException { if (s == null) { throw new NullPointerException("Your passed a null argument"); }/*from w w w.j av a 2 s .c o m*/ Character firstChar = s.charAt(0); String theRest = s.substring(1); return firstChar.toString().toUpperCase() + theRest; }