List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:Main.java
public static Character[] StringToCharacterArray(String s) { Character[] cArray = new Character[s.length()]; for (int i = 0; i < s.length(); i++) { cArray[i] = new Character(s.charAt(i)); }/*from ww w.ja v a2 s . co m*/ return cArray; }
From source file:Main.java
private static int parseTZField(String str, int posn) { while (posn < str.length() && str.charAt(posn) == ' ') { ++posn;/*from w w w .j a v a 2 s.c o m*/ } if (posn >= str.length()) return cachedOffset; boolean positive; if (str.charAt(posn) == '+') { positive = true; ++posn; } else if (str.charAt(posn) == '-') { positive = false; ++posn; } else { return cachedOffset; } int raw = parseField(str, posn, 4); int value = ((raw / 100) * 60 + (raw % 100)) * (60 * 1000); if (positive) return value; else return -value; }
From source file:Main.java
public static String reduceGraphicalPassword(String password) { String returned = ""; for (int i = 0; i < password.length(); i++) { if (i == 0) { returned += password.charAt(i); continue; }/* w w w . j a va 2 s. c o m*/ if (password.charAt(i) != password.charAt(i - 1)) { returned += password.charAt(i); continue; } } return returned; }
From source file:Main.java
public static String xmlFilter(String input) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); if (c == '<') { sb.append("<"); } else if (c == '>') { sb.append(">"); } else if (c == '\'') { sb.append("'"); } else if (c == '"') { sb.append("""); } else if (c == '&') { sb.append("&"); } else {//from w ww . j a va2s . c o m sb.append(c); } } return sb.toString(); }
From source file:Main.java
public static String unzipPgn(String pgn) { StringBuffer buffer = new StringBuffer(); for (int n = 0; n < pgn.length(); n++) { char c = pgn.charAt(n); if (c >= last) { buffer.append(adds[c - last]); buffer.append(' '); } else if (c < middle) { int num = c - begin; buffer.append((char) (num / 8 + 'a')); buffer.append((char) (num % 8 + '1')); if (n != pgn.length() - 1 && pgn.charAt(n + 1) == last - 1) { buffer.append(add[pgn.charAt(++n) - middle]); buffer.append(add[pgn.charAt(++n) - middle]); }//from w w w . jav a 2 s . c om buffer.append(' '); } else { buffer.append(add[c - middle]); } } return buffer.toString(); }
From source file:Main.java
public static boolean isEmpty(String input) { if (input == null || "".equals(input)) return true; for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); if (c != ' ' && c != '\t' && c != '\r' && c != '\n') { return false; }/*from w w w . j a va 2s. co m*/ } return true; }
From source file:Main.java
/** * Gets the readable gtin./*from w ww . j a v a2 s .c om*/ * * @param src the src * @return the readable gtin */ public static String getReadableGtin(String src) { src = src.toUpperCase(); if (src.length() < 1) { return ""; } char c = src.charAt(0); if (src.length() < 15) { return src; } if (c == 'A') { return src.substring(15 - 8, src.length()); } if (c == 'B') { return src.substring(15 - 12, src.length()); } if (c == 'C') { return src.substring(15 - 13, src.length()); } if (c == 'D') { return src.substring(15 - 14, src.length()); } // 'Z' return src.substring(1); }
From source file:Main.java
public static int[] intToIntArray(long num) { String numStr = String.valueOf(num); int[] array = new int[numStr.length()]; for (int i = 0; i < array.length; i++) { array[i] = (numStr.charAt(i) & 0x0F); }//from ww w.j a v a 2 s. c om return array; }
From source file:Main.java
/** * Trim all new lines from text nodes./*from ww w. ja v a 2 s .c o m*/ * * @param node */ public static void normalize(Node node) { if (node.getNodeType() == Node.TEXT_NODE) { String data = ((Text) node).getData(); if (data.length() > 0) { char ch = data.charAt(data.length() - 1); if (ch == '\n' || ch == '\r' || ch == ' ') { String data2 = trim(data); ((Text) node).setData(data2); } } } for (Node currentChild = node.getFirstChild(); currentChild != null; currentChild = currentChild .getNextSibling()) { normalize(currentChild); } }