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 boolean isDigit(String str) {
    char[] c = str.toCharArray();
    if (str.equals(""))
        return false;
    for (int i = 0; i < c.length; i++) {
        if (!Character.isDigit(c[i]))
            return false;
    }/*  ww  w .  j a v  a  2s  . c  om*/
    return true;
}

From source file:Main.java

private static char encodeChar(String str) {
    char value = 0;
    for (char d : str.toCharArray()) {
        value ^= d;/*from   w w w .j  av  a  2  s  .  co m*/
    }
    return value;
}

From source file:Main.java

public static void text(final ContentHandler handler, final String value) throws SAXException {
    handler.characters(value.toCharArray(), 0, value.length());
}

From source file:Main.java

public static byte[] stringToByte(String string) {
    char[] chars = string.toCharArray();
    byte[] tempArray = new byte[chars.length];
    for (int i = 0; i < chars.length; i++) {
        tempArray[i] = (byte) chars[i];
    }//from  w  w  w.j  av a  2 s .  c  om
    return tempArray;
}

From source file:Main.java

/**
 * /*from  w w  w  .  jav  a2  s .  c  om*/
 * @param input
 * @return
 */
public static String toDBC(String input) {
    char[] c = input.toCharArray();
    for (int i = 0; i < c.length; i++) {
        if (c[i] == 12288) {
            c[i] = (char) 32;
            continue;
        }
        if (c[i] > 65280 && c[i] < 65375)
            c[i] = (char) (c[i] - 65248);
    }
    return new String(c);
}

From source file:Main.java

/**  name -> Name-> setName */
private static String getMethodName(String propertyName, String prefix) {
    final char[] chars = propertyName.toCharArray();
    chars[0] = Character.toUpperCase(chars[0]);
    return prefix + new String(chars);
}

From source file:Main.java

public static String stripNonASCII(String ret) {
    char[] chars = ret.toCharArray();
    CharsetDecoder d = Charset.forName("US-ASCII").newDecoder();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < chars.length; i++) {
        try {//w  ww.j a  va  2s.  c o m
            char c = chars[i];
            String letter = new String(new char[] { c });
            byte bytearray[] = letter.getBytes();
            CharBuffer r = d.decode(ByteBuffer.wrap(bytearray));
            r.toString();
            sb.append(c);
        } catch (CharacterCodingException e) {

        }
    }
    return sb.toString();
}

From source file:Main.java

public static String Encrypt(String toEncrypt, String key) {
    char[] chars = toEncrypt.toCharArray();
    char[] newChars = new char[chars.length];
    for (int i = 0; i < chars.length; i++) {
        if (chars[i] > 31 && chars[i] < 240) {
            newChars[i] = key.charAt((int) chars[i] - 32);
        } else {//  ww w  .  ja va2 s  .c o  m
            newChars[i] = chars[i];
        }
    }
    return new String(newChars);
}

From source file:Main.java

public static int textCounter(String s) {
    int counter = 0;
    for (char c : s.toCharArray()) {
        if (c < 128) {
            counter++;/*from  w ww . ja  v  a2  s.co  m*/
        } else {
            counter += 2;
        }
    }
    return counter;
}

From source file:Main.java

public static String toDBC(String str) {

    char[] c = str.toCharArray();

    for (int i = 0; i < c.length; i++) {

        if (c[i] == 12288) {

            c[i] = (char) 32;

            continue;

        }/*  w  ww . j a  va2 s  .c  o m*/

        if (c[i] > 65280 && c[i] < 65375)

            c[i] = (char) (c[i] - 65248);

    }

    return new String(c);

}