List of usage examples for java.lang String toCharArray
public char[] toCharArray()
From source file:com.google.u2f.TestUtils.java
public static byte[] parseHex(String hexEncoded) { try {/*from w w w . java 2 s .co m*/ return Hex.decodeHex(hexEncoded.toCharArray()); } catch (DecoderException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * Removes all tags from the given text. * @param text The text to remove tags from. * @return The text without tags./* ww w . j ava2 s . c o m*/ */ public static String removeTags(String text) { if (text != null) { StringBuffer sb = new StringBuffer(); char[] signs = text.toCharArray(); boolean inTag = false; boolean inAttribute = false; for (char sign : signs) { if (!inTag) { if (sign == '<') { inTag = true; } else { sb.append(sign); } } else { if (sign == '>' && !inAttribute) { inTag = false; inAttribute = false; } else if (sign == '\'' || sign == '"') { inAttribute = !inAttribute; } } } return sb.toString(); } else { return null; } }
From source file:Main.java
/** * Simply converts the the five reserved XML characters (<,>,",\,&) into * their escaped counterparts./*from w ww. j a v a 2 s . co m*/ */ public static final String escape(String str) { if (str == null) return null; StringBuffer b = new StringBuffer(); final char[] chars = str.toCharArray(); final int len = chars.length; int st; for (int i = 0; i < len; i++) { st = findChar(chars[i]); if (st != -1) b.append(entityStrings[st]); else b.append(chars[i]); } return b.toString(); }
From source file:com.opengamma.integration.viewer.status.AggregateType.java
private static boolean hasDepulicateChar(String aggregateStrType) { char[] aggregateTypeChars = aggregateStrType.toCharArray(); Set<Character> uniqueChars = Sets.newHashSet(); for (Character character : aggregateTypeChars) { uniqueChars.add(character);/*from w ww. j a v a 2 s .co m*/ } return uniqueChars.size() != VALID_AGGRAGATION_CHARS.size(); }
From source file:net.paygate.saml.util.RequestUtil.java
/** * Returns HTML encoded version of the specified String s. * //from www .j av a2 s. co m * @param s String to be HTML encoded * @return HTML encoded String */ public static String htmlEncode(String s) { StringBuffer encodedString = new StringBuffer(""); char[] chars = s.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (c == '<') { encodedString.append("<"); } else if (c == '>') { encodedString.append(">"); } else { encodedString.append(c); } } return encodedString.toString(); }
From source file:Main.java
public static String remove(String str, char remove) { if (isEmpty(str) || str.indexOf(remove) == -1) { return str; }/*w w w .j av a 2 s. c o m*/ char[] chars = str.toCharArray(); int pos = 0; for (int i = 0; i < chars.length; i++) { if (chars[i] != remove) { chars[pos++] = chars[i]; } } return new String(chars, 0, pos); }
From source file:Main.java
/** * Converts String to boolean array/* w ww .j ava 2s. co m*/ * @param data * @param charsetSize * @return */ public static boolean[] data2Binary(String data, int charsetSize) { boolean[] bits = new boolean[data.length() * charsetSize]; int index = 0; for (char c : data.toCharArray()) { int asciiVal = (int) c; System.out.print(c + ":" + asciiVal + " "); asciiVal <<= 1; // throw away most left bit. (is always a 0, cfr. ASCII-table) for (int i = 0; i < charsetSize; i++) { bits[index] = (asciiVal & (int) Math.pow(2, charsetSize)) == 0 ? false : true; System.out.print(bits[index] + " "); asciiVal <<= 1; // throw away left most bit index++; } System.out.println(); } return bits; }
From source file:Main.java
/** * Replace the not support emoji.//from w w w. j ava2 s .c o m * @param str * @return */ public static String matchEmojiUnicode(String str) { if (TextUtils.isEmpty(str)) { return str; } char[] charArray = str.toCharArray(); try { for (int i = 0; i < charArray.length - 1; i++) { int _index = charArray[i]; int _index_inc = charArray[i + 1]; if (_index == 55356) { if ((_index_inc < 56324) || (_index_inc > 57320)) { continue; } charArray[i] = '.'; charArray[(i + 1)] = '.'; } if ((_index != 55357) || (_index_inc < 56343) || (_index_inc > 57024)) { continue; } charArray[i] = '.'; charArray[(i + 1)] = '.'; } } catch (Exception e) { } return new String(charArray); }
From source file:Base64Coder.java
/** * Decodes a Base64 string.//from www .j a v a2 s . c o m * * @param s * a Base64 String to be decoded. * @return A String containing the decoded data. * @throws IllegalArgumentException * if the input is not valid Base64 encoded data. */ public static String decode(String s) { return new String(decode(s.toCharArray())); }
From source file:Strings.java
/** * Returns <code>true</code> if the specified string contains * only whitespace characters./*from ww w. j ava 2 s. c om*/ * * @param s Stirng to test for whitespace. * @return <code>true</code> if the specified string contains only * whitespace characters. */ public static boolean allWhitespace(String s) { return allWhitespace(s.toCharArray(), 0, s.length()); }