Example usage for java.lang String toCharArray

List of usage examples for java.lang String toCharArray

Introduction

In this page you can find the example usage for java.lang String toCharArray.

Prototype

public char[] toCharArray() 

Source Link

Document

Converts this string to a new character array.

Usage

From source file:Main.java

/**
 * Wraps illegal characters(in XML) to CData.
 * Example: /* www  . j a v  a2s.c o m*/
 * String: Bonnie & Clyde should result in String:
 * Bonnie <![CDATA[&]]> Clyde
 * */
public static String wrapToCData(String s) {
    if (s != null) {
        StringBuilder builder = new StringBuilder();
        char[] chars = s.toCharArray();
        for (char c : chars) {
            if (illegalChars.contains(c)) {
                builder.append("<![CDATA[" + c + "]]>");
            } else {
                builder.append(c);
            }
        }
        return builder.toString();
    } else {
        return null;
    }
}

From source file:Main.java

public static boolean isUnicodeSurrogate(String word) { // emoji icons are within these surrogate areas
    if (word != null && word.length() == 2) {
        char[] chArray = word.toCharArray();
        return Character.isSurrogatePair(chArray[0], chArray[1]);
    }/* w w  w .ja v a 2 s  .c o  m*/
    return false;

}

From source file:Main.java

public static String checkAndChangeFileName(String sInput) {
    String CheckedAndChangedName = "";
    // sInput = sInput.toUpperCase();
    char[] cInput = sInput.toCharArray();

    for (int i = 0; i < sInput.length(); i++) {
        if (cInput[i] == '0' || cInput[i] == '1' || cInput[i] == '2' || cInput[i] == '3' || cInput[i] == '4'
                || cInput[i] == '5' || cInput[i] == '6' || cInput[i] == '7' || cInput[i] == '8'
                || cInput[i] == '9' || cInput[i] == 'a' || cInput[i] == 'b' || cInput[i] == 'c'
                || cInput[i] == 'd' || cInput[i] == 'e' || cInput[i] == 'f' || cInput[i] == 'g'
                || cInput[i] == 'h' || cInput[i] == 'i' || cInput[i] == 'j' || cInput[i] == 'k'
                || cInput[i] == 'l' || cInput[i] == 'm' || cInput[i] == 'n' || cInput[i] == 'o'
                || cInput[i] == 'p' || cInput[i] == 'q' || cInput[i] == 'r' || cInput[i] == 's'
                || cInput[i] == 't' || cInput[i] == 'u' || cInput[i] == 'v' || cInput[i] == 'w'
                || cInput[i] == 'x' || cInput[i] == 'y' || cInput[i] == 'z' || cInput[i] == 'A'
                || cInput[i] == 'B' || cInput[i] == 'C' || cInput[i] == 'D' || cInput[i] == 'E'
                || cInput[i] == 'F' || cInput[i] == 'G' || cInput[i] == 'H' || cInput[i] == 'I'
                || cInput[i] == 'J' || cInput[i] == 'K' || cInput[i] == 'L' || cInput[i] == 'M'
                || cInput[i] == 'N' || cInput[i] == 'O' || cInput[i] == 'P' || cInput[i] == 'Q'
                || cInput[i] == 'R' || cInput[i] == 'S' || cInput[i] == 'T' || cInput[i] == 'U'
                || cInput[i] == 'V' || cInput[i] == 'W' || cInput[i] == 'X' || cInput[i] == 'Y'
                || cInput[i] == 'Z' || cInput[i] == '.' || cInput[i] == '_') {
            CheckedAndChangedName += cInput[i];
        }/*from  w ww . j a va2 s  .c o  m*/
    }
    return CheckedAndChangedName;
}

From source file:Main.java

/**
 * XML comment does not support some characters inside its content but there is no official escaping/unescaping for
 * it so we made our own./*from w w w  .  ja v  a  2 s . co  m*/
 * <p>
 * <ul>
 * <li>1) Escape existing \</li>
 * <li>2) Escape --</li>
 * <li>3) Add "\" (unescaped as "") at the end if the last char is -</li>
 * </ul>
 * 
 * @param content the XML comment content to escape
 * @return the escaped content.
 * @since 1.9M2
 */
public static String escapeXMLComment(String content) {
    StringBuffer str = new StringBuffer(content.length());

    char[] buff = content.toCharArray();
    char lastChar = 0;
    for (char c : buff) {
        if (c == '\\') {
            str.append('\\');
        } else if (c == '-' && lastChar == '-') {
            str.append('\\');
        }

        str.append(c);
        lastChar = c;
    }

    if (lastChar == '-') {
        str.append('\\');
    }

    return str.toString();
}

From source file:Main.java

public static void testChecksum(String inputString, String expectedSum) throws Exception {
    byte[] sample = Hex.decodeHex(inputString.toCharArray());
    byte[] sampleCheckSum = Hex.decodeHex(expectedSum.toCharArray());
    char checksum = checkSum(sample);
    byte[] result = { (byte) (checksum & 0xFF), (byte) ((checksum >> 8) & 0xFF) };
    System.out.println("Calculated checksum: " + byteArrayToString(result) + " vs expected: " + expectedSum);

    // Confirmation
    char checksumComp = (char) (checksum ^ 0xFFFF);
    byte verifySample[] = Arrays.copyOf(sample, sample.length + 2);
    verifySample[verifySample.length - 4] = (byte) (checksumComp & 0xFF);
    verifySample[verifySample.length - 3] = (byte) (checksumComp >> 8);
    char verifier = checkSum(verifySample);
    byte[] verifierResult = { (byte) (verifier & 0xFF), (byte) ((verifier >> 8) & 0xFF) };
    System.out.println("Verifier = " + byteArrayToString(verifierResult));
}

From source file:Main.java

public static String escapeXml(String doco) {
    if (doco == null)
        return "";

    StringBuilder b = new StringBuilder();
    for (char c : doco.toCharArray()) {
        if (c == '<')
            b.append("&lt;");
        else if (c == '>')
            b.append("&gt;");
        else if (c == '&')
            b.append("&amp;");
        else if (c == '"')
            b.append("&quot;");
        else//from  ww  w.j  a v a  2  s  .  c om
            b.append(c);
    }
    return b.toString();
}

From source file:com.cmri.bpt.common.util.EncodeUtil.java

/**
 * Hex?./*from   ww  w .  java2  s.c o m*/
 */
public static byte[] decodeHex(String input) {
    try {
        return Hex.decodeHex(input.toCharArray());
    } catch (DecoderException e) {
        throw ExceptionUtil.asUnChecked(e);
    }
}

From source file:com.mycompany.monroelabsm.B58.java

public static byte[] hexToBytes(String s) throws DecoderException {
    return Hex.decodeHex(s.toCharArray());
}

From source file:Main.java

public static ArrayList<String> retrieveLinks(String text) {
    ArrayList<String> links = new ArrayList<String>();

    String regex = "\\(?\\b(http://|www[.])[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(text);/*from www .  j  a v a  2s .c om*/
    while (m.find()) {
        String urlStr = m.group();

        if (urlStr.startsWith("(") && urlStr.endsWith(")")) {

            char[] stringArray = urlStr.toCharArray();

            char[] newArray = new char[stringArray.length - 2];
            System.arraycopy(stringArray, 1, newArray, 0, stringArray.length - 2);
            urlStr = new String(newArray);
            System.out.println("Finally Url =" + newArray.toString());

        }
        System.out.println("...Url..." + urlStr);
        links.add(urlStr);
    }
    return links;
}

From source file:Main.java

/**
 *
 * @throws InvalidKeySpecException//from  w  ww. j a va2s . c  o m
 * @throws NoSuchAlgorithmException
 */
private static Key deriveKeyPbkdf2(byte[] salt, String password)
        throws InvalidKeySpecException, NoSuchAlgorithmException {

    KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, ITERATION_COUNT, KEY_LENGTH);
    SecretKeyFactory factory;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1And8bit");
    } else {
        factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    }

    byte[] keyBytes = factory.generateSecret(keySpec).getEncoded();

    return new SecretKeySpec(keyBytes, "AES");
}