List of usage examples for java.lang String charAt
public char charAt(int index)
From source file:com.epam.jdi.uitests.mobile.appium.driver.ScreenshotMaker.java
public static String getValidUrl(String logPath) { if (logPath == null || logPath.equals("")) return ""; String result = logPath.replace("/", "\\"); if (result.charAt(1) != ':') if (result.substring(0, 3).equals("..\\")) result = result.substring(2); if (result.charAt(0) != '\\') result = "\\" + result; if (result.charAt(result.length() - 1) != '\\') result = result + "\\"; return StringUtils.correctPath(result); }
From source file:Main.java
public static boolean isNumeric(Object obj) { if (obj == null) { return false; }/*from w ww .j ava 2s .c o m*/ String str = obj.toString(); int sz = str.length(); for (int i = 0; i < sz; i++) { if (!Character.isDigit(str.charAt(i))) { return false; } } return true; }
From source file:Main.java
public static String escapeXml(String payload) { StringBuilder out = new StringBuilder(); for (int i = 0; i < payload.length(); i++) { char c = payload.charAt(i); if ((c == 0x9) || (c == 0xA) || (c == 0xD) || ((c >= 0x20) && (c <= 0xD7FF)) || ((c >= 0xE000) && (c <= 0xFFFD)) || ((c >= 0x10000) && (c <= 0x10FFFF))) out.append(c);/* w w w . jav a 2 s . c o m*/ } return out.toString(); }
From source file:Main.java
public static int APHash(String str) { int hash = 0; for (int i = 0; i < str.length(); i++) { hash ^= ((i & 1) == 0) ? ((hash << 7) ^ str.charAt(i) ^ (hash >> 3)) : (~((hash << 11) ^ str.charAt(i) ^ (hash >> 5))); }/* www. ja v a 2 s . c o m*/ // return (hash & 0x7FFFFFFF); return hash; }
From source file:Main.java
private static void frequenceyCount(String input) { Map<Character, Integer> hashCount = new HashMap<>(); Character c;//from w w w .j av a2 s . c om for (int i = 0; i < input.length(); i++) { c = input.charAt(i); if (hashCount.get(c) != null) { hashCount.put(c, hashCount.get(c) + 1); } else { hashCount.put(c, 1); } } Iterator it = hashCount.entrySet().iterator(); System.out.println("char : frequency"); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); System.out.println(pairs.getKey() + " : " + pairs.getValue()); it.remove(); } }
From source file:com.marklogic.contentpump.utilities.XMLUtil.java
/** * Get valid element name from a given string * @param name//from w w w .ja v a 2 s . c o m * @return */ public static String getValidName(String name) { StringBuilder validname = new StringBuilder(); char ch = name.charAt(0); if (!XML11Char.isXML11NameStart(ch)) { LOG.warn("Prepend _ to " + name); validname.append("_"); } for (int i = 0; i < name.length(); i++) { ch = name.charAt(i); if (!XML11Char.isXML11Name(ch)) { LOG.warn("Character " + ch + " in " + name + " is converted to _"); validname.append("_"); } else { validname.append(ch); } } return validname.toString(); }
From source file:Main.java
/** * capitalize first letter// w w w . j a v a 2 s. c o m * * <pre> * capitalizeFirstLetter(null) = null; * capitalizeFirstLetter("") = ""; * capitalizeFirstLetter("2ab") = "2ab" * capitalizeFirstLetter("a") = "A" * capitalizeFirstLetter("ab") = "Ab" * capitalizeFirstLetter("Abc") = "Abc" * </pre> * * @param str * @return */ public static String capitalizeFirstLetter(String str) { if (isEmpty(str)) { return str; } char c = str.charAt(0); return (!Character.isLetter(c) || Character.isUpperCase(c)) ? str : new StringBuilder(str.length()).append(Character.toUpperCase(c)).append(str.substring(1)) .toString(); }
From source file:Main.java
public static String escape(String str) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (h.containsKey(c)) { sb.append(h.get(c));//from ww w . ja v a 2 s . c om } else { sb.append(c); } } return sb.toString(); }
From source file:Main.java
private static boolean containsInvalidHostnameAsciiCodes(String hostnameAscii) { for (int i = 0; i < hostnameAscii.length(); i++) { char c = hostnameAscii.charAt(i); if (c <= '\u001f' || c >= '\u007f') { return true; }/*from w w w.j a va 2 s . c o m*/ if (" #%/:?@[\\]".indexOf(c) != -1) { return true; } } return false; }
From source file:Main.java
public static String utf16to8(String str) { int i = 0, len = str.length(), c; String out = ""; while (i < len) { c = str.charAt(i); if ((c >= 0x0001) && (c <= 0x007F)) { out += str.charAt(i);/* w w w .ja va2 s . c o m*/ } else if (c > 0x07FF) { out += (char) (0xE0 | ((c >> 12) & 0x0F)); out += (char) (0x80 | ((c >> 6) & 0x3F)); out += (char) (0x80 | (c & 0x3F)); } else { out += (char) (0xC0 | ((c >> 6) & 0x1F)); out += (char) (0x80 | (c & 0x3F)); } i++; } return out; }