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 String toSBC(String s) {
    if (isEmpty(s))
        return s;
    char[] chars = s.toCharArray();
    for (int i = 0, len = chars.length; i < len; i++) {
        if (chars[i] == ' ') {
            chars[i] = (char) 12288;
        } else if (33 <= chars[i] && chars[i] <= 126) {
            chars[i] = (char) (chars[i] + 65248);
        } else {//from  w  ww . j  a v  a 2  s  .  c  o m
            chars[i] = chars[i];
        }
    }
    return new String(chars);
}

From source file:com.dlej.Main.java

public static List<Character> asList(String str) {
    return Arrays.asList(ArrayUtils.toObject(str.toCharArray()));
}

From source file:Unicode2ASCII.java

public static String toHTML(String unicode) {
    String output = "";

    char[] charArray = unicode.toCharArray();

    for (int i = 0; i < charArray.length; ++i) {
        char a = charArray[i];
        if ((int) a > 255) {
            output += "&#" + (int) a + ";";
        } else {/*from   w w w  .jav a2 s .  c  o m*/
            output += a;
        }
    }
    return output;
}

From source file:Main.java

public static String hideUsernameString(String username) {
    String clone = new String(username);
    char us[] = username.toCharArray();
    if (username.length() > 5) {
        for (int i = 2; i < username.length() - 2; i++) {
            us[i] = '*';
            clone = new String(us);
        }//from  www.j a v  a2  s .  co  m
    } else {
        for (int i = 1; i < username.length(); i++) {
            us[i] = '*';
            clone = new String(us);

        }
    }

    return clone;
}

From source file:Main.java

public static String escape(String text) {
    StringBuffer sb = new StringBuffer();
    for (char c : text.toCharArray()) {
        escape(c, sb);// w w  w.j a v a2 s.  c  o m
    }
    return sb.toString();
}

From source file:Unicode2ASCII.java

public static String toJAVA(String unicode) {
    String output = "";

    char[] charArray = unicode.toCharArray();

    for (int i = 0; i < charArray.length; ++i) {
        char a = charArray[i];
        if ((int) a > 255) {
            output += "\\u" + Integer.toHexString((int) a);
        } else {//from   w  w  w.  j ava 2  s. com
            output += a;
        }
    }

    return output;
}

From source file:Main.java

public static String capitalize(String text) {
    boolean capitalizeNextChar = true;
    char[] array = text.toCharArray();
    for (int i = 0; i < array.length; i++) {
        Character c = text.charAt(i);
        if (splitChar.contains(c))
            capitalizeNextChar = true;/*from   w w  w .j a va 2s . c  o m*/
        else if (capitalizeNextChar) {
            array[i] = Character.toUpperCase(array[i]);
            capitalizeNextChar = false;
        }
    }
    return new String(array);
}

From source file:Main.java

public static String removeDesiredDigit(String numStr, char digit) {
    StringBuilder builder = new StringBuilder();
    for (char c : numStr.toCharArray()) {
        if (c != digit) {
            builder.append(c);/*from   w  ww . j  av  a  2 s  . c  om*/
        }
    }
    return builder.toString();
}

From source file:Main.java

public static String escape(String text) {
    StringBuilder sb = new StringBuilder();
    for (char c : text.toCharArray()) {
        escape(c, sb);/*from ww  w.ja  va  2 s .  c o  m*/
    }
    return sb.toString();
}

From source file:Main.java

public static String toInitCap(String param) {

    if (param != null && param.length() > 0) {
        char[] charArray = param.toCharArray(); // convert into char array
        charArray[0] = Character.toUpperCase(charArray[0]); // set capital
        // letter to
        // first/* w  ww.  j  a  v  a2 s .  com*/
        // postion
        return new String(charArray); // return desired output
    } else {
        return "";
    }
}