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[] fromHexString(String hexString) {
    char[] chars = hexString.toCharArray();
    byte[] result = new byte[chars.length / 2];
    for (int i = 0; i < result.length; i++) {
        char c = chars[2 * i];
        int a = ((Character.isDigit(c) ? c - '0' : c - 'A' + 10) << 4) & 0xF0;
        c = chars[2 * i + 1];// w  w w  .  j av a2 s  .  c om
        int b = (Character.isDigit(c) ? c - '0' : c - 'A' + 10) & 0x0F;
        result[i] = (byte) ((a | b) & 0xFF);
    }
    return result;
}

From source file:Main.java

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

From source file:Main.java

public static String replaceString(String paramString, int paramInt) {
    char[] arrayOfChar = paramString.toCharArray();
    int i = paramString.length();
    for (int j = 0;; j++) {
        if (j >= paramInt)
            return String.valueOf(arrayOfChar);
        arrayOfChar[(-5 + (i - j))] = '*';
    }//from w w  w  .j  a  va2  s.c om
}

From source file:Main.java

public static String toASCIILowerCase(String string) {
    char[] charArray = string.toCharArray();
    StringBuilder sb = new StringBuilder(charArray.length);
    for (int index = 0; index < charArray.length; index++) {
        if ('A' <= charArray[index] && charArray[index] <= 'Z') {
            sb.append((char) (charArray[index] + ('a' - 'A')));
        } else {/*from   w  w  w  .j a v a 2s  .  co  m*/
            sb.append(charArray[index]);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String toASCIIUpperCase(String string) {
    char[] charArray = string.toCharArray();
    StringBuilder sb = new StringBuilder(charArray.length);
    for (int index = 0; index < charArray.length; index++) {
        if ('a' <= charArray[index] && charArray[index] <= 'z') {
            sb.append((char) (charArray[index] - ('a' - 'A')));
        } else {//from w w  w  .j a v a 2  s.c o m
            sb.append(charArray[index]);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static byte[] toBytes(String s) {
    return toBytes(s.toCharArray());
}

From source file:Main.java

public static char getLargestDigit(String numStr) {
    char largest = '0';
    for (char c : numStr.toCharArray()) {
        if (c > largest)
            largest = c;//from  ww  w  .  java 2 s .  c  o  m
    }

    return largest;
}

From source file:Main.java

public static char getSmallerDigit(String numStr) {
    char smallest = '9';
    for (char c : numStr.toCharArray()) {
        if (c < smallest)
            smallest = c;/*  w w w  .j  av a  2  s . co  m*/
    }

    return smallest;
}

From source file:Main.java

public static int getChineseNum(String s) {

    int num = 0;/*from   ww  w .  java 2 s.c om*/
    char[] myChar = s.toCharArray();
    for (int i = 0; i < myChar.length; i++) {
        if ((char) (byte) myChar[i] != myChar[i]) {
            num++;
        }
    }
    return num;
}

From source file:Main.java

public static String replace(String string, char oldchar, char newchar) {
    char chars[] = string.toCharArray();
    for (int w = 0; w < chars.length; w++) {
        if (chars[w] == oldchar) {
            chars[w] = newchar;//  w w  w.ja v a 2 s  . c  o  m
            break;
        }
    }
    return new String(chars);
}