List of usage examples for java.lang String toCharArray
public char[] toCharArray()
From source file:Main.java
/** * Tries to parse the port of a host string. If no port could be parsed -1 is * returned.//from ww w.j av a 2 s.co m * @param hostName the full host string. * @return the port as an int or -1. */ public static int parsePort(String hostName) { int portIdx = hostName.indexOf(':'); if (portIdx == -1) { return -1; } String portString = hostName.substring(portIdx + 1); char[] data = portString.toCharArray(); int port = 0; for (char c : data) { // '0' '9' if (c < 48 || c > 57) { // !digit break; } // shift left and add value port = port * 10 + c - '0'; } // no port or out of range if (!isPortInRange(port)) { return -1; } return port; }
From source file:com.myb.portal.util.Encodes.java
/** * Hex?.//from w ww . j av a 2s .c om */ public static byte[] decodeHex(String input) { try { return Hex.decodeHex(input.toCharArray()); } catch (DecoderException e) { // throw Exceptions.unchecked(e); } return null; }
From source file:io.lavagna.model.util.ShortNameGenerator.java
private static int countUpperCase(String s) { int cnt = 0;// w w w . j av a 2 s.co m for (char c : s.toCharArray()) { if (Character.isUpperCase(c)) { cnt++; } } return cnt; }
From source file:Main.java
public static String convertChoice(String c) { if (c.equals("-1")) return "--"; String rs = ""; char[] cs = c.toCharArray(); for (int i = 0; i < cs.length; i++) { if (cs[i] == '0') rs += "A,"; else if (cs[i] == '1') rs += "B,"; else if (cs[i] == '2') rs += "C,"; else if (cs[i] == '3') rs += "D,"; else if (cs[i] == '4') rs += "E,"; else if (cs[i] == '5') rs += "F,"; else if (cs[i] == '6') rs += "G,"; }/* w w w.j a v a 2 s . c o m*/ if (rs.equals("")) return "--"; else return rs.substring(0, rs.lastIndexOf(',')); }
From source file:Main.java
private static String capitalize(String str) { if (TextUtils.isEmpty(str)) { return str; }//from w ww . j a va2s . c o m char[] arr = str.toCharArray(); boolean capitalizeNext = true; String phrase = ""; for (char c : arr) { if (capitalizeNext && Character.isLetter(c)) { phrase += Character.toUpperCase(c); capitalizeNext = false; continue; } else if (Character.isWhitespace(c)) { capitalizeNext = true; } phrase += c; } return phrase; }
From source file:Main.java
/** * <p>/*ww w .j a v a 2s.c o m*/ * Encodes the given text in a way that it contains no XML elements * and can be used for instance as plain text or attribute value. * </p> * <p> * The following signs are replaced: * <pre> * " => "quot; * & => "amp; * ' => "apos; * < => "lt; * > => "gt; * </pre> * </p> * @param text The text to encode. * @return The encoded text. */ public static String encodeText(String text) { if (text != null) { char[] signs = text.toCharArray(); StringBuffer sb = new StringBuffer(); for (char sign : signs) { switch (sign) { case '"': sb.append("""); break; case '&': sb.append("&"); break; case '\'': sb.append("'"); break; case '<': sb.append("<"); break; case '>': sb.append(">"); break; default: sb.append(sign); break; } } return sb.toString(); } else { return null; } }
From source file:com.quui.chat.Preprocessor.java
/** * @param message the string to check for non ascii * @return true is string contains non-ascii, else false *//*from ww w . j a v a 2 s . co m*/ static public boolean containsNonAscii(String message) { char[] m = message.toCharArray(); for (int i = 0; i < m.length; i++) { if (m[i] < 0 || m[i] > 127) { return true; } } return false; }
From source file:Main.java
public static byte[] createSaltedHash(String input, byte[] salt) throws InvalidKeySpecException, NoSuchAlgorithmException { char[] inputToCharArray = input.toCharArray(); return doPBKDF2(inputToCharArray, salt, PBKDF2_ITERATIONS, HASH_LENGTH); }
From source file:Main.java
public static String halfWidthToFullWidth(String s) { if (isEmpty(s)) { return s; }/*w ww. j av a 2s .com*/ char[] source = s.toCharArray(); for (int i = 0; i < source.length; i++) { if (source[i] == ' ') { source[i] = (char) 12288; // } else if (source[i] == '.') { // source[i] = (char)12290; } else if (source[i] >= 33 && source[i] <= 126) { source[i] = (char) (source[i] + 65248); } else { source[i] = source[i]; } } return new String(source); }
From source file:Main.java
/** Parse a version string such as "1.1.6" or "jdk1.2fcs" into a version array of integers {1, 1, 6} or {1, 2}. A string of "n." or "n..m" is equivalent to "n.0" or "n.0.m" respectively. *//* w ww .jav a 2s. com*/ public static int[] parseVersion(String version) { if (version == null) return new int[0]; char[] s = version.toCharArray(); //find the maximum span of the string "n.n.n..." where n is an integer int start = 0; for (; start < s.length && (s[start] < '0' || s[start] > '9'); ++start) if (start == s.length) //no digit found return new int[0]; int end = start + 1; int size = 1; for (; end < s.length; ++end) if (s[end] == '.') ++size; else if (s[end] < '0' || s[end] > '9') break; int[] val = new int[size]; for (int i = 0; i < size; ++i) { int dot = version.indexOf('.', start); if (dot == -1 || dot > end) dot = end; if (start >= dot) //cases like "n." or "n..m" val[i] = 0; //convert equivalent to "n.0" or "n.0.m" else val[i] = Integer.parseInt(version.substring(start, dot)); start = dot + 1; } return val; }