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

/**
 * /*from w  w w  .  j  av a2 s.  c om*/
 * Checks if the String contains any character in the given set of characters.
 * 
 * 
 * 
 * A <code>null</code> String will return <code>false</code>. A <code>null</code> search string will return
 * <code>false</code>.
 * 
 * 
 * <pre>
 * StringUtils.containsAny(null, *)            = false
 * StringUtils.containsAny("", *)              = false
 * StringUtils.containsAny(*, null)            = false
 * StringUtils.containsAny(*, "")              = false
 * StringUtils.containsAny("zzabyycdxx", "za") = true
 * StringUtils.containsAny("zzabyycdxx", "by") = true
 * StringUtils.containsAny("aba","z")          = false
 * </pre>
 * 
 * @param str
 *            the String to check, may be null
 * @param searchChars
 *            the chars to search for, may be null
 * @return the <code>true</code> if any of the chars are found, <code>false</code> if no match or null input
 * @since 2.4
 */
public static boolean containsAny(String str, String searchChars) {
    if (searchChars == null) {
        return false;
    }
    return containsAny(str, searchChars.toCharArray());
}

From source file:Main.java

/**
 * Convert hex string to byte[]//from  w  w  w  .j  a  va  2s . c  om
 * 
 * @param hexString
 *            the hex string
 * @return byte[]
 */
public static byte[] hexStringToBytes(String hexString) {
    if (hexString == null || hexString.equals("")) {
        return null;
    }
    hexString = hexString.toUpperCase();
    int length = hexString.length() / 2;
    char[] hexChars = hexString.toCharArray();
    byte[] d = new byte[length];
    for (int i = 0; i < length; i++) {
        int pos = i * 2;
        d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
    }
    return d;
}

From source file:com.weblyzard.lib.string.nilsimsa.Nilsimsa.java

private static byte[] _getByteArray(String hexString) {
    try {//from   w w w.  j  a v a  2  s  .  c om
        return Hex.decodeHex(hexString.toCharArray());
    } catch (DecoderException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.censoredsoftware.library.util.StringUtil2.java

/**
 * Checks the <code>string</code> for <code>max</code> capital letters.
 *
 * @param string the string to check./*  w w w  . j  a  v a2 s.c  o m*/
 * @param max    the maximum allowed capital letters.
 */
public static boolean hasCapitalLetters(String string, int max) {
    // Define variables
    String allCaps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int count = 0;
    char[] characters = string.toCharArray();
    for (char character : characters) {
        if (allCaps.contains("" + character))
            count++;
        if (count > max)
            return true;
    }
    return false;
}

From source file:fr.paris.lutece.util.bean.BeanUtil.java

/**
 * Remove underscore and set the next letter in caps
 * @param strSource The source//w  w  w  . j av  a 2  s .  c  om
 * @return The converted string
 */
public static String convertUnderscores(String strSource) {
    StringBuilder sb = new StringBuilder();
    boolean bCapitalizeNext = false;

    for (char c : strSource.toCharArray()) {
        if (c == UNDERSCORE) {
            bCapitalizeNext = true;
        } else {
            if (bCapitalizeNext) {
                sb.append(Character.toUpperCase(c));
                bCapitalizeNext = false;
            } else {
                sb.append(c);
            }
        }
    }

    return sb.toString();
}

From source file:Main.java

/**
 * Translates a Java file name to a XML file name according
 * to Android naming convention./*from ww  w  .  j  a  v a 2s .  c  om*/
 *
 * Doesn't append .xml extension
 *
 * @return XML file name associated with Java file name
 */
public static String getXmlFileNameFromJavaFileName(String javaFileName) {

    if (javaFileName.endsWith(".java")) {
        // cut off ".java"
        javaFileName = javaFileName.substring(0, javaFileName.length() - 5);
    }

    char[] charsJava = javaFileName.toCharArray();
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < charsJava.length; i++) {
        char currentChar = charsJava[i];
        if (Character.isUpperCase(currentChar) && i != 0) {
            stringBuilder.append('_');
        }
        stringBuilder.append(Character.toLowerCase(currentChar));
    }
    return stringBuilder.toString();
}

From source file:com.feedzai.commons.sql.abstraction.util.AESHelper.java

/**
 * Decrypts a byte[] encrypted by {@link #encrypt} method.
 *
 * @param c   The encrypted HEX byte[]./*  ww  w. j  a va 2s.  c om*/
 * @param key The key.
 * @return The decrypted string in a byte[].
 */
public static byte[] decrypt(byte[] c, String key) {
    try {
        SecretKeySpec skeySpec = new SecretKeySpec(Hex.decodeHex(key.toCharArray()), "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, skeySpec);
        return cipher.doFinal(Hex.decodeHex((new String(c).toCharArray())));
    } catch (Exception e) {
        logger.warn("Could not decrypt byte[]", e);
        return null;
    }
}

From source file:com.feedzai.commons.sql.abstraction.util.AESHelper.java

/**
 * Decrypts a string encrypted by {@link #encrypt} method.
 *
 * @param c   The encrypted HEX string./*w ww .j av  a2 s . c  o  m*/
 * @param key The  key.
 * @return The decrypted string.
 */
public static String decrypt(String c, String key) {
    try {
        SecretKeySpec skeySpec = new SecretKeySpec(Hex.decodeHex(key.toCharArray()), "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, skeySpec);
        byte[] decoded = cipher.doFinal(Hex.decodeHex(c.toCharArray()));
        return new String(decoded);
    } catch (Exception e) {
        logger.warn("Could not decrypt string", e);
        return null;
    }
}

From source file:Main.java

public static byte[] hexStringToByteArray(String encoded) {
    if ((encoded.length() % 2) != 0)
        throw new IllegalArgumentException("Input string must contain an even number of characters");

    final byte result[] = new byte[encoded.length() / 2];
    final char enc[] = encoded.toCharArray();
    for (int i = 0; i < enc.length; i += 2) {
        StringBuilder curr = new StringBuilder(2);
        curr.append(enc[i]).append(enc[i + 1]);
        result[i / 2] = (byte) Integer.parseInt(curr.toString(), 16);
    }/*from   w  ww . j av  a 2 s  . c om*/
    return result;
}