List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:Main.java
public static String reverse(String input) { StringBuilder output = new StringBuilder(); for (int i = input.length() - 1; i >= 0; i--) { output.append(input.charAt(i)); }/*from ww w . ja v a 2 s. com*/ return output.toString(); }
From source file:Main.java
/** * Tell whether the string contains a positive or negative number * delta, i.e., a number with an obligatory + or - sign. *//*from ww w .j av a 2s. c o m*/ public static boolean isNumberDelta(String string) { String s = string.trim(); if (s.length() < 2) return false; return (s.charAt(0) == '+' || s.charAt(0) == '-') && isUnsignedNumber(s.substring(1)); }
From source file:Main.java
protected static String display(byte[] array) { char[] val = new char[2 * array.length]; String hex = "0123456789abcdef"; for (int i = 0; i < array.length; i++) { int b = array[i] & 0xff; val[2 * i] = hex.charAt(b >>> 4); val[2 * i + 1] = hex.charAt(b & 15); }/*from w w w . j a v a 2 s.com*/ return String.valueOf(val); }
From source file:Main.java
/** * Encode a String for XML output, displaying it to a PrintWriter. * The String to be encoded is displayed, except that * special characters are converted into entities. * @param input a String to convert.//from w w w. ja v a 2 s . co m * @param out a PrintWriter to which to write the results. */ public static void stringEncodeXML(String input, PrintWriter out) { for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); switch (c) { case '<': case '>': case '"': case '\'': case '&': case '\t': case '\n': case '\r': out.print("&#" + (int) c + ";"); break; default: out.print(c); } } }
From source file:Main.java
/** * Check whether the parameter is effective compression IPv6 address. * * @param input IPV6 address./* w ww. j ava 2s .c o m*/ * @return True or false. * @see #isIPv6StdAddress(String) */ public static boolean isIPv6HexCompressedAddress(final String input) { int colonCount = 0; for (int i = 0; i < input.length(); i++) { if (input.charAt(i) == ':') { colonCount++; } } return colonCount <= 7 && IPV6_HEX_COMPRESSED_PATTERN.matcher(input).matches(); }
From source file:Main.java
/** * Scan to ")", return position following the ")". * @param domainsAtt/* w ww. ja v a 2s . co m*/ * @param p * @return position of character following the ")". */ private static int parseParens(String domainsAtt, int p) { char c = domainsAtt.charAt(p); while (p < domainsAtt.length()) { switch (c) { case ')': p++; break; default: p++; } } return p; }
From source file:Main.java
public static String getter2property(String methodName) { if (methodName.startsWith("get") && methodName.length() > 3) { return Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); }/*from w w w.ja v a2 s .c o m*/ if (methodName.startsWith("is") && methodName.length() > 2) { return Character.toLowerCase(methodName.charAt(2)) + methodName.substring(3); } return null; }
From source file:Main.java
private static byte bits2byte(String bString) { byte result = 0; for (int i = bString.length() - 1, j = 0; i >= 0; i--, j++) { result += (Byte.parseByte(bString.charAt(i) + "") * Math.pow(2, j)); }/*from w ww . ja v a 2 s. com*/ return result; }
From source file:Main.java
public static String string2HexString(String str) { StringBuffer hexString = new StringBuffer(); for (int i = 0; i < str.length(); i++) { int ch = (int) str.charAt(i); String strHex = Integer.toHexString(ch); hexString.append(strHex);/* w w w .j a v a 2 s .c om*/ } return hexString.toString(); }
From source file:Main.java
public static int DEKHash(String str) { int hash = str.length(); for (int i = 0; i < str.length(); i++) { hash = ((hash << 5) ^ (hash >> 27)) ^ str.charAt(i); }//from ww w . ja va2s. c om return (hash & 0x7FFFFFFF); }