List of usage examples for java.lang String toCharArray
public char[] toCharArray()
From source file:Main.java
public static String getVehicleName(String input) { if (TextUtils.isEmpty(input)) return ""; char[] c = input.toCharArray(); for (int i = 0; i < c.length; i++) { if (c[i] == 12288) { c[i] = (char) 32; continue; }/*from w ww . j ava 2s .co m*/ if (c[i] > 65280 && c[i] < 65375) c[i] = (char) (c[i] - 65248); } return new String(c); }
From source file:Main.java
public static String removeCharInc(String str, String inc) { if (str == null) { return str; }//from w w w . j a va 2s . c o m char[] carr = str.toCharArray(); StringBuffer buf = new StringBuffer(); for (int idx = 0; idx < carr.length; idx++) { if (inc.indexOf(carr[idx]) != -1) { buf.append(carr[idx]); } } return buf.toString(); }
From source file:Main.java
/** * Converts the String to a UNICODE byte array. It will also add the ending * null characters to the end of the string. * @param s the string to convert/*from w ww.j ava 2 s.c o m*/ * @return the unicode byte array of the string */ public static byte[] convertToUnicodeByteArray(String s) { if (s == null) { return null; } char c[] = s.toCharArray(); byte[] result = new byte[(c.length * 2) + 2]; for (int i = 0; i < c.length; i++) { result[(i * 2)] = (byte) (c[i] >> 8); result[((i * 2) + 1)] = (byte) c[i]; } // Add the UNICODE null character result[result.length - 2] = 0; result[result.length - 1] = 0; return result; }
From source file:Main.java
public static String setPoint(String in) { char[] res;//from ww w . j av a 2 s. c o m char[] cur = in.toCharArray(); boolean isNeg = in.contains("-"); int lengthNum; if (isNeg) lengthNum = in.length() - 1; else lengthNum = in.length(); int length = in.length() - NUM_AFTER_COM; if (lengthNum > NUM_AFTER_COM) { res = new char[in.length() + 1]; res[length] = '.'; System.arraycopy(cur, 0, res, 0, length); System.arraycopy(cur, length, res, length + 1, NUM_AFTER_COM); } else { int size; if (isNeg) { length = in.length() - 1; size = NUM_AFTER_COM + 3; res = new char[size]; res[0] = '-'; res[1] = '0'; res[2] = '.'; System.arraycopy(cur, 1, res, size - length, length); } else { length = in.length(); size = NUM_AFTER_COM + 2; res = new char[size]; res[0] = '0'; res[1] = '.'; System.arraycopy(cur, 0, res, size - length, length); } for (int i = 0; i < res.length; i++) { if (res[i] == '\u0000') res[i] = '0'; } } return new String(res); }
From source file:Main.java
/** * Changes a non-ascii string into an HTML encoded ascii string. * * @param notAscii The string to change. * * @return The converted string.//from ww w .ja va 2 s . c o m */ public static String toAscii(String notAscii) { StringBuilder builder = new StringBuilder(); char[] charArray = notAscii.toCharArray(); for (int i = 0; i < charArray.length; ++i) { char a = charArray[i]; if ((int) a > 255) { builder.append("&#" + (int) a + ";"); } else { builder.append(a); } } return builder.toString(); }
From source file:Main.java
public static Map<String, List<String>> createDictionary(Context context) { try {/*from ww w .jav a2 s. co m*/ AssetManager am = context.getAssets(); InputStream is = am.open(DICTIONARY_FILENAME); Scanner reader = new Scanner(is); Map<String, List<String>> map = new HashMap<String, List<String>>(); while (reader.hasNextLine()) { String word = reader.nextLine(); char[] keyArr = word.toCharArray(); Arrays.sort(keyArr); String key = String.copyValueOf(keyArr); List<String> wordList = map.get(key); if (wordList == null) { wordList = new LinkedList<String>(); } wordList.add(word); map.put(key, wordList); } reader.close(); return map; } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } return null; }
From source file:PasswordServlet.java
public static byte[] hexToBytes(String hex) { return hexToBytes(hex.toCharArray()); }
From source file:Main.java
public static boolean isNullOrWhiteSpace(String str) { if (str == null || str.isEmpty()) { return true; }/* ww w. ja v a 2 s. co m*/ for (char c : str.toCharArray()) { if (!Character.isWhitespace(c)) { return false; } } return true; }
From source file:Main.java
public static boolean isChineseByREG(String str) { boolean isChinese = true; char[] ch = str.toCharArray(); for (int i = 0; i < ch.length; i++) { char c = ch[i]; if (isChinese(c)) { } else {/*from w w w . ja v a2 s . co m*/ isChinese = false; break; } } return isChinese; }
From source file:com.ejwa.dinja.utility.ArrayHelperTest.java
private static Character[] toCharArray(String string) { return ArrayUtils.toObject(string.toCharArray()); }