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:Rot13.java

/**
 * Converts the input string ROT-13 algorithm.
 * @param inStr The input string./*from w  w  w.  jav  a 2s.  c  o  m*/
 * @return The ROT-13ed version of the input string.
 */
public static String cipher(final String inStr) {
    char[] arr = inStr.toCharArray();
    StringBuilder sb = new StringBuilder(arr.length);

    for (char c : arr) {
        Character out = map.get(c);
        if (out == null) {
            sb.append(c);
        } else {
            sb.append(out);
        }
    }

    return sb.toString();
}

From source file:Main.java

public static void escape(StringBuilder sb, String string) {
    escape(sb, string.toCharArray(), 0, string.length());
}

From source file:Main.java

public static int countLength(String string) {
    int length = 0;
    char[] chars = string.toCharArray();
    for (int w = 0; w < string.length(); w++) {
        char ch = chars[w];
        if (ch >= '\u0391' && ch <= '\uFFE5') {
            length++;/*from w w  w.ja va  2s.  c o  m*/
            length++;
        } else {
            length++;
        }
    }
    return length;
}

From source file:Unicode2ASCII.java

public static String toHTML(String unicode) {
    String tc = unicode;
    String output = "";
    char[] ca = tc.toCharArray();
    for (int i = 0; i < ca.length; ++i) {
        char a = ca[i];
        if ((int) a > 255) {
            output += "&#" + (int) a + ";";
        } else {//w w  w. j a v  a  2  s .c o m
            output += a;
        }
    }
    return output;
}

From source file:Unicode2ASCII.java

public static String toJAVA(String unicode) {
    String tc = unicode;
    String output = "";
    char[] ca = tc.toCharArray();
    for (int i = 0; i < ca.length; ++i) {
        char a = ca[i];
        if ((int) a > 255) {
            output += "\\u" + Integer.toHexString((int) a);
        } else {/*  ww  w .  ja va 2s.  c o m*/
            output += a;
        }
    }
    return output;
}

From source file:Main.java

public static String getStringToNumber(String value) {
    StringBuffer sbu = new StringBuffer();
    char[] chars = value.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        {/* w  w w. j  ava2s  .com*/
            sbu.append(msg.get("" + chars[i]));
        }
    }
    return sbu.toString();
}

From source file:Main.java

public static boolean isValidNCName(String name) {
    boolean ret = true;
    for (char c : name.toCharArray()) {
        boolean isMinusc = ('a' <= c && c <= 'z');
        boolean isMajusc = ('A' <= c && c <= 'Z');
        boolean isDigit = ('0' <= c && c <= '9');
        boolean isSpecialChar = (c == '.' || c == '-' || c == '_');
        ret = !(isMinusc || isMajusc || isDigit || isSpecialChar);
        if (!ret)
            break;
    }/*ww w.ja v  a 2 s .  co  m*/
    return ret;
}

From source file:Main.java

public static byte[] convertStringToBytes(String str) {
    byte[] bytes = new byte[str.length() * Character.SIZE];
    System.arraycopy(str.toCharArray(), 0, bytes, 0, bytes.length);
    return bytes;
}

From source file:Main.java

public static String stringToAscii(String val) {
    StringBuffer stringBuffer = new StringBuffer();
    char[] chars = val.toCharArray();

    for (int i = 0; i < chars.length; i++) {
        stringBuffer.append((int) chars[i]);
    }/*from w w w . j ava 2 s.  com*/

    return stringBuffer.toString();
}

From source file:Main.java

public static boolean isChinaLanguage(String str) {
    char[] chars = str.toCharArray();
    int[] ints = new int[2];
    boolean isChinese = false;
    int length = chars.length;
    byte[] bytes = null;
    for (int i = 0; i < length; i++) {
        bytes = ("" + chars[i]).getBytes();
        if (bytes.length == 2) {
            ints[0] = bytes[0] & 0xff;
            ints[1] = bytes[1] & 0xff;
            if (ints[0] >= 0x81 && ints[0] <= 0xFE && ints[1] >= 0x40 && ints[1] <= 0xFE) {
                isChinese = true;//www . j  a  v a2s.c  om
            }
        } else {
            return false;
        }
    }
    return isChinese;
}