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

public static byte[] hexStringToBytes(String hexString) {
    if (hexString == null || hexString.equals("")) {
        return null;
    }//from   w  w w  .  j  a va2s  .c om
    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:Main.java

public static String longestCommonStringImproved(String str1, String str2) {
    if (str1 == null || str2 == null || str1.length() == 0 || str2.length() == 0)
        return null;

    char[] cc1 = str1.toCharArray();
    char[] cc2 = str2.toCharArray();

    int[][] table = new int[cc1.length + 1][cc2.length + 1];
    int startIndex = 0, maxLength = 0;

    for (int i = 0; i < cc1.length; i++) {
        for (int j = 0; j < cc2.length; j++) {
            calledTimes++;//from  w w w  . jav a2 s  . c  om
            if (cc1[i] == cc2[j]) {
                if (i == 0 || j == 0)
                    table[i + 1][j + 1] = 1;
                else {
                    table[i + 1][j + 1] = table[i][j] + 1;
                }
                if (table[i + 1][j + 1] > maxLength) {
                    maxLength = table[i + 1][j + 1];
                    startIndex = i;
                }
            }
        }
    }

    // abcd  bcd
    return str1.substring(startIndex + 1 - maxLength, startIndex + 1);
}

From source file:arena.utils.Base64.java

/**
 * Expects the classic base64 "abcdefgh=" syntax (equals padded)
 * and decodes it to original form//  w  w  w.jav  a 2s.  c  om
 */
public static byte[] decodeBase64(String input) {
    char[] inBytes = input.toCharArray();
    byte[] outBytes = new byte[(int) (inBytes.length * 0.75f)]; // always mod 4 = 0

    LogFactory.getLog(Base64.class)
            .debug("Base64 decoding: in=" + inBytes.length + " chars, out=" + outBytes.length + " bytes");
    int length = decodeBase64(inBytes, outBytes);
    byte returnValue[] = new byte[length];
    System.arraycopy(outBytes, 0, returnValue, 0, length);
    return returnValue;
}

From source file:cl.whyem.testsutilityproject.otpgenerator.KeyBase.java

protected static byte[] dec(String val) {
    try {//from w  w w  . j a  v  a 2  s.  c om
        return Hex.decodeHex(val.toCharArray());
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
}

From source file:com.sangupta.andruil.utils.ArgumentUtils.java

/**
 * Check if the given argument represents a number or not.
 * /*from  ww w  .j  a va 2  s. c  o  m*/
 * @param arg
 * @return
 */
public static boolean isNumber(String arg) {
    if (arg == null) {
        return false;
    }

    char[] num = arg.toCharArray();
    int index = 0;
    char c;
    for (; index < num.length; index++) {
        c = num[index];
        if (c < '0' || c > '9' || c != '-' || c != '+' || c != '.') {
            return false;
        }
    }

    return true;
}

From source file:gov.va.vinci.leo.tools.XmlFilter.java

/**
 * Return a copy of the input string with non XML-1.0 characters replaced by spaces.
 *
 * @param str Input string whose text will be filtered.
 * @return Filtered copy of the input string
 *//*w  w w .j  a v  a  2s .c o m*/
public static String toXml10(final String str) {
    StringBuilder sb = new StringBuilder(str.length());
    char[] chars = str.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (XMLUtils.checkForNonXmlCharacters(chars, i, 1, false) == -1) {
            sb.append(chars[i]);
        } else {
            sb.append(' ');
        } //else
    } //for
    return sb.toString();
}

From source file:Main.java

/**
 * Pretty crap long hashcode algo. FIXME
 * @param s The string to get the long hash code for
 * @return the long has code/*from   www  .ja v a 2 s  .co m*/
 */
public static long longHashCode(String s) {
    long h = 0;
    int len = s.length();
    int off = 0;
    int hashPrime = s.hashCode();
    char val[] = s.toCharArray();
    for (int i = 0; i < len; i++) {
        h = (31 * h + val[off++] + (hashPrime * h));
    }
    return h;
}

From source file:cn.hxh.springside.utils.EncodeUtils.java

/**
 * Hex?, String->byte[].//from   w  ww.j a  v a2  s  .c o m
 */
public static byte[] decodeHex(String input) {
    try {
        return Hex.decodeHex(input.toCharArray());
    } catch (DecoderException e) {
        throw new IllegalStateException("Hex Decoder exception", e);
    }
}

From source file:com.sangupta.andruil.utils.ArgumentUtils.java

/**
 * Check if a given argument has wild-cards present in it or not.
 * //from  www. j ava 2 s  . c o m
 * @param arg
 * @return
 */
public static boolean hasWildcards(String arg) {
    if (arg == null) {
        return false;
    }

    char[] name = arg.toCharArray();
    int index = 0;
    char c;
    for (; index < name.length; index++) {
        c = name[index];
        if (c == '*' || c == '?') {
            return true;
        }
    }

    return false;
}

From source file:info.bonjean.beluga.util.CryptoUtil.java

public static String pandoraDecrypt(String text) {
    try {/*from  www.  j a  v  a2s .  co  m*/
        return new String(decryptBlowfish(Hex.decodeHex(text.toCharArray()), DECRYPT_KEY)).trim();
    } catch (DecoderException e) {
        log.error(e.getMessage(), e);
        return null;
    }
}