List of usage examples for java.lang String toCharArray
public char[] toCharArray()
From source file:com.lehman.ic9.common.hex.java
/** * Decodes the provided data and returns a byte[] with the * decoded data./*from ww w .j a v a 2 s .c o m*/ * @param str is a hex encoded String. * @return A byte[] with the decoded bytes. * @throws ic9exception Exception */ public static byte[] decode(String str) throws ic9exception { try { return Hex.decodeHex(str.toCharArray()); } catch (DecoderException e) { throw new ic9exception("hex.decode(): " + e.getMessage()); } }
From source file:Main.java
public static String fullWidthToHalfWidth(String s) { if (isEmpty(s)) { return s; }// w w w . j a va2s . c om char[] source = s.toCharArray(); for (int i = 0; i < source.length; i++) { if (source[i] == 12288) { source[i] = ' '; // } else if (source[i] == 12290) { // source[i] = '.'; } else if (source[i] >= 65281 && source[i] <= 65374) { source[i] = (char) (source[i] - 65248); } else { source[i] = source[i]; } } return new String(source); }
From source file:Main.java
public static byte[] toBytes(String hex) { int len = (hex.length() / 2); byte[] result = new byte[len]; char[] achar = hex.toCharArray(); for (int i = 0; i < len; i++) { int pos = i * 2; result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1])); }//ww w . jav a 2s .co m return result; }
From source file:Main.java
/** * Escapes string for XML.// w w w. j a v a 2s. c o m * * @param in input string * @return escaped string */ private static String escape(String in) { StringBuilder sb = new StringBuilder(); for (char c : in.toCharArray()) { switch (c) { case '&': sb.append("&"); break; case 0xA0: // \n sb.append(" "); break; case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '"': sb.append("""); break; default: sb.append(c); } } return sb.toString(); }
From source file:com.ad.mediasharing.tvmclient.AESEncryption.java
private static SecretKeySpec getKey(String key) throws Exception { return new SecretKeySpec(Hex.decodeHex(key.toCharArray()), "AES"); }
From source file:Main.java
public static String ToDBC(String input) { if (TextUtils.isEmpty(input)) { return ""; }/*from w w w . j a v a2 s . c o m*/ char[] c = input.toCharArray(); for (int i = 0; i < c.length; i++) { if (c[i] == 12288) { c[i] = (char) 32; continue; } if (c[i] > 65280 && c[i] < 65375) c[i] = (char) (c[i] - 65248); } return new String(c); }
From source file:Main.java
/** * Converts the given number into a char-array. If the length of the array * is shorter than the required exact length, the array is padded with leading * '0' chars. If the array is longer than the wanted length the most * significant digits are cut off until the array has the exact length. * * @param number The number to convert to a char array. * @param exactArrayLength The exact length of the returned array. * @return The numebr as char array, one char for each decimal digit. * @preconditions (exactArrayLength >= 0) * @postconditions (result <> null) * and (result.length == exactArrayLength) *///from w w w . ja va 2 s . c o m public static char[] toCharArray(int number, int exactArrayLength) { char[] charArray = null; String numberString = Integer.toString(number); char[] numberChars = numberString.toCharArray(); if (numberChars.length > exactArrayLength) { // cut off digits beginning at most significant digit charArray = new char[exactArrayLength]; for (int i = 0; i < charArray.length; i++) { charArray[i] = numberChars[i]; } } else if (numberChars.length < exactArrayLength) { // pad with '0' leading chars charArray = new char[exactArrayLength]; int offset = exactArrayLength - numberChars.length; for (int i = 0; i < charArray.length; i++) { charArray[i] = (i < offset) ? '0' : numberChars[i - offset]; } } else { charArray = numberChars; } return charArray; }
From source file:Main.java
@NonNull public static String[] partStringByChar(@NonNull String str) { String[] chars = new String[str.length()]; char[] charArray = str.toCharArray(); for (int i = 0; i < chars.length; i++) { chars[i] = new String(charArray, i, 1); }//from ww w .jav a2s . c o m return chars; }
From source file:Main.java
public static byte[] ConvertStringToHexBytes(String StringToConvert) { char[] CharArray = StringToConvert.toCharArray(); char[] Char = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; int result = 0; byte[] ConvertedString = new byte[] { (byte) 0x00, (byte) 0x00 }; for (int i = 0; i <= 1; i++) { for (int j = 0; j <= 15; j++) { if (CharArray[i] == Char[j]) { if (i == 1) { result = result + j; j = 15;//w w w. ja va 2 s . c o m } else if (i == 0) { result = result + j * 16; j = 15; } } } } ConvertedString[0] = (byte) result; result = 0; for (int i = 2; i <= 3; i++) { for (int j = 0; j <= 15; j++) { if (CharArray[i] == Char[j]) { if (i == 3) { result = result + j; j = 15; } else if (i == 2) { result = result + j * 16; j = 15; } } } } ConvertedString[1] = (byte) result; return ConvertedString; }
From source file:Main.java
/** * XML encode a string.//w w w .j a v a2 s . c o m * @param str the string to encode. * @return the encoded string. */ public static String escapeContent(String str) { final StringBuilder b = new StringBuilder(); final char[] chars = str.toCharArray(); for (int i = 0; i < chars.length; ++i) { final char c = chars[i]; switch (c) { case '<': b.append("<"); break; case '>': b.append(">"); break; case '&': b.append("&"); break; default: b.append(c); } } return b.toString(); }