List of usage examples for java.lang String toCharArray
public char[] toCharArray()
From source file:Main.java
public static byte[] ConvertStringToHexBytes(String StringToConvert) { StringToConvert = StringToConvert.toUpperCase(); StringToConvert = StringToConvert.replaceAll(" ", ""); 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;//from w ww. j av a2s . co 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
/** * <p>Parses the specified {@link String} <code>str</code> with the given * delimiter <code>delim</code> and returns an array of {@link String} * delimited by the said delimiter. Note that this method takes into * account characters escaped by a backslash.</p> * * @param str/*from w w w . j av a2 s . c o m*/ * @param delim * @return {@link String}[] */ public static String[] parseStringWithEscappedDelimiter(String str, char delim) { int i = 0; int state = 0; char c; int prev = 0; boolean firstTime = true; char[] testStringarr = str.toCharArray(); List<String> strList = new ArrayList<String>(5); for (int len = testStringarr.length; i < len; i++) { c = testStringarr[i]; if (state == 0) { if (c == '\\') { state++; } else if (c == delim) { if (firstTime) { strList.add(str.substring(prev, i)); } else { strList.add(str.substring(prev + 1, i)); } if (prev == 0) { firstTime = false; } prev = i; } } else { state--; } } if (firstTime) { strList.add(str.substring(prev)); } else { strList.add(str.substring(prev + 1)); } return strList.toArray(new String[strList.size()]); }
From source file:Base64.java
public static byte[] decode(String data) { return decode(data.toCharArray()); }
From source file:Main.java
public static boolean hasString(Reader reader, String string, char c) throws IOException { if (DEBUG)//from w ww . j a va 2 s . co m System.out.println("XMLParserUtilities.hasString( " + reader + ", " + string + ", " + c + ")"); char[] chars = string.toCharArray(); for (int i = 0; i < chars.length; i++) { if (DEBUG) System.out.print(c); if (chars[i] != c) { if (DEBUG) System.out.println("XMLParserUtilities.hasString() [false]"); return false; } if ((i + 1) < chars.length) { c = (char) reader.read(); } } if (DEBUG) System.out.println("XMLParserUtilities.hasString() [true]"); return true; }
From source file:edu.uoa.cs.master.cloudmanufacturingnlp.util.Tools.java
/** * Remove the suffix of a String. e.g. companyB-2, E. * //from ww w. j ava2s .c om * @param originalString * @return */ public static String removeDashSuffix(String originalString) { // remove suffix of dash int posOfDash = originalString.lastIndexOf("-"); if (posOfDash == -1) { return originalString; } String suffix = originalString.substring(posOfDash + 1, originalString.length()); for (char character : suffix.toCharArray()) { if ((character < '0') || (character > '9')) { return originalString; } } String stringWithoutDash = originalString.substring(0, posOfDash); // remove suffix of full stop if (stringWithoutDash.endsWith(".")) { return stringWithoutDash.substring(0, stringWithoutDash.length() - 1); } return stringWithoutDash; }
From source file:com.networknt.light.util.HashUtil.java
public static String generateStorngPasswordHash(String password) throws NoSuchAlgorithmException, InvalidKeySpecException { int iterations = 1000; char[] chars = password.toCharArray(); byte[] salt = getSalt().getBytes(); PBEKeySpec spec = new PBEKeySpec(chars, salt, iterations, 64 * 8); SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); byte[] hash = skf.generateSecret(spec).getEncoded(); return iterations + ":" + toHex(salt) + ":" + toHex(hash); }
From source file:com.silverwrist.dynamo.servlet.BrowserDatabaseEntry.java
/** * Preprocesses the header string, turning it from an MS-DOS style "glob" pattern into a proper * regular expression.//w ww . j a v a2s . c o m * * @param header The header field to preprocess. * @return The preprocessed header. */ private static final String preprocess(String header) { StringBuffer buf = new StringBuffer(); char[] src = header.toCharArray(); for (int i = 0; i < src.length; i++) { // turn the DOS-style glob characters into a proper regular expression if (src[i] == '*') buf.append(".*"); else if (src[i] == '?') buf.append('.'); else { // append the character, possibly escaped if (s_special_chars.contains(src[i])) buf.append('\\'); buf.append(src[i]); } // end else } // end for return buf.toString(); }
From source file:CompTest.java
public static Comparator stringComparator() { return new Comparator() { public int compare(Object o1, Object o2) { String s1 = (String) o1; String s2 = (String) o2; int len1 = s1.length(); int len2 = s2.length(); int n = Math.min(len1, len2); char v1[] = s1.toCharArray(); char v2[] = s2.toCharArray(); int pos = 0; while (n-- != 0) { char c1 = v1[pos]; char c2 = v2[pos]; if (c1 != c2) { return c1 - c2; }//w w w .jav a 2 s.c om pos++; } return len1 - len2; } }; }
From source file:com.maddyhome.idea.vim.helper.StringHelper.java
/** * Check if the text matches the CharData production from the XML grammar. * * This check is more restricted than CharData as it completely forbids '>'. */// ww w. ja va 2 s . com public static boolean isXmlCharacterData(@NotNull String text) { for (char c : text.toCharArray()) { if (!isXmlChar(c) || c == '<' || c == '>' || c == '&') { return false; } } return true; }
From source file:com.screenslicer.common.HtmlCoder.java
public static String encode(String string) { try {/*from www. j av a 2 s . co m*/ StringBuilder builder = new StringBuilder(); for (int i = 0; i < string.length();) { int codePoint = string.codePointAt(i); String symbol = codePointToSymbol(codePoint); char[] chars = symbol.toCharArray(); if (chars.length == 1 && CharUtils.isAscii(chars[0])) { builder.append(StringEscapeUtils.escapeHtml4(Character.toString(chars[0]))); } else { builder.append(symbol); } i += chars.length; } return builder.toString(); } catch (Throwable t) { Log.exception(t); return string; } }