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

private static void initCharTable(String charStr) {
    char[] chars = charStr.toCharArray();
    for (char c : chars) {
        CHAR_TABLE[c] = encodeChar(c);/*from w w  w .jav  a2s  . c  o m*/
    }
}

From source file:Main.java

/**
 * Determines if argument is a number/*from  www. j av a2 s .  com*/
 * @param string - argument to test
 * @return - true if argument is a number
 */
public static boolean isNumber(String string) {
    boolean result = true;
    char[] chars = string.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (!Character.isDigit(chars[i])) {
            result = false;
        }
    }
    return result;
}

From source file:Main.java

public static String hexStrToStr(String hexStr) {
    String str = "0123456789ABCDEF";
    char[] hexs = hexStr.toCharArray();
    byte[] bytes = new byte[hexStr.length() / 2];
    int n;//  www.  j  ava2s .  c o m

    for (int i = 0; i < bytes.length; i++) {
        n = str.indexOf(hexs[2 * i]) * 16;
        n += str.indexOf(hexs[2 * i + 1]);
        bytes[i] = (byte) (n & 0xff);
    }
    return new String(bytes);
}

From source file:Main.java

public static String getASCII(String value) {
    StringBuffer sbu = new StringBuffer();
    char[] chars = value.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (i != chars.length - 1) {
            sbu.append((int) chars[i]);
        }//from w  w w.ja  v  a  2 s.  co  m
    }
    return sbu.toString();
}

From source file:Main.java

public static String replaceUpCase(String str) {
    StringBuffer sb = new StringBuffer();
    char[] c = str.toCharArray();
    for (int i = 0; c != null && i < c.length; i++) {
        if (i == 0) {
            sb.append(("" + c[i]).toUpperCase());
        } else if (c[i] < 97) {
            sb.append(("_" + c[i]));
        } else {/*  ww w.  jav  a2  s  .c  o  m*/
            sb.append(c[i]);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static boolean isNumeric(String str) {
    if (str == null)
        return false;

    for (char c : str.toCharArray()) {
        if (!Character.isDigit(c))
            return false;
    }/*from   www .j av a  2s . co  m*/
    return true;
}

From source file:Main.java

/**
 * Generates a SecretKey.//w  w  w .j  ava 2 s .c om
 */
public static SecretKey newSecretKey(String algorithm, String password) {
    return newSecretKey(algorithm, new PBEKeySpec(password.toCharArray()));
}

From source file:Main.java

public static String hexToString(String hex) {
    StringBuilder sb = new StringBuilder();
    char[] hexData = hex.toCharArray();
    for (int count = 0; count < hexData.length - 1; count += 2) {
        int firstDigit = Character.digit(hexData[count], 16);
        int lastDigit = Character.digit(hexData[count + 1], 16);
        int decimal = firstDigit * 16 + lastDigit;
        sb.append((char) decimal);
    }/*from   w ww . j  av a 2s .c o m*/
    return sb.toString();
}

From source file:Main.java

/**
 * VLC only acccepts "-._~" in Mrl format, android Uri accepts "_-!.~'()*".
 * Therefore, encode the characters authorized by Android Uri when creating a mrl from an Uri.
 *///from  www  .  j  av  a2s  . c o m
public static String encodeVLCString(@NonNull String mrl) {
    final char[] array = mrl.toCharArray();
    final StringBuilder sb = new StringBuilder(array.length * 2);

    for (final char c : array) {
        if (URI_AUTHORIZED_CHARS.indexOf(c) != -1)
            sb.append("%").append(Integer.toHexString(c));
        else
            sb.append(c);
    }
    return sb.toString();
}

From source file:Main.java

public static int countOccurence(String matchedString, char occurence) {
    int count = 0;
    for (final char c : matchedString.toCharArray()) {
        if (c == occurence) {
            ++count;//from   ww w  . j  a  v a2 s . c om
        }
    }
    return count;
}