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 getPowerNumberString(String string) {
    String Current = string.replaceAll(" ", "");

    char[] chars = Current.toCharArray();
    String number = "";
    for (int i = 8; i < chars.length - 4; i++) {
        number += chars[i];/*from   w  ww .ja  v  a2 s.  c om*/
    }
    return number;
}

From source file:Main.java

public static String decode(String str) {
    char ch[] = str.toCharArray();
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < ch.length; i++) {
        if (ch[i] == '/' || ch[i] == '\\' || ch[i] == '"' || ch[i] == '?' || ch[i] == '*' || ch[i] == '<'
                || ch[i] == '>' || ch[i] == ':')
            continue;
        if (ch[i] == '%') {
            if (i + 2 < ch.length) {
                int c = Integer.parseInt(ch[i + 1] + "" + ch[i + 2], 16);
                buf.append((char) c);
                i += 2;/*from  w w w . jav a 2 s  .com*/
                continue;
            }
        }
        buf.append(ch[i]);
    }
    return buf.toString();
}

From source file:Main.java

public static int getSSIDLength(String ssid) {
    int count = 0;
    char[] chars = ssid.toCharArray();
    for (char c : chars) {
        if (isChinese(c)) {
            count += 3;/*from   www.  ja v a2s  . com*/
        } else {
            count++;
        }
    }
    return count;
}

From source file:Main.java

/**
 * Generates a common hashname for joined
 * columns/*from   w  w  w.  j a v  a 2  s . c  o m*/
 * @param hashes List of column hashes
 * @return common hash
 */
public static String createCommonName(List<String> hashes) {
    int[] nums = new int[SIZE_DBHASH];
    char[] valids = VALID_DBHASH_CHARS.toCharArray();
    StringBuilder sb = new StringBuilder();

    for (String hash : hashes) {
        char[] cur = hash.toCharArray();
        for (int i = 0; i < SIZE_DBHASH; i++)
            nums[i] += cur[i];
    }

    for (int num : nums)
        sb.append(valids[num % valids.length]);

    return sb.toString();
}

From source file:Main.java

public static byte computeChecksum(String s) {
    byte checksum = 0;
    for (char c : s.toCharArray()) {
        checksum ^= (byte) c;
    }/*from w  ww .j a va2s . c o  m*/
    return checksum;
}

From source file:Main.java

public static int getCharOccurance(String input, char c) {
    int occurance = 0;
    char[] chars = input.toCharArray();
    for (char thisChar : chars) {
        if (thisChar == c) {
            occurance++;/*from ww w  . j  a v  a2s  .co m*/
        }
    }
    return occurance;
}

From source file:Main.java

/**
 * Write characters. Character data is properly escaped.
 * //w w w  .  j a va 2  s.c  o m
 * @param out
 *            The writer.
 * @param value
 *            The text as a strng.
 */
public static void writeCharacters(PrintWriter out, String value) {
    writeCharacters(out, value.toCharArray(), 0, value.length());
}

From source file:Main.java

/**
 * Converts any numbers and punctuation into standard ASCII
 * @param inputString/*from   www  .j a v  a 2  s  .c  o m*/
 * @return
 */
static public String normalizeNumbersAndPunctuation(String inputString) {
    char[] chars = inputString.toCharArray();

    for (int curCharNum = 0; curCharNum < chars.length; curCharNum++) {
        char curChar = chars[curCharNum];
        if (Character.isDigit(curChar)) {
            int curDigit = Integer.parseInt(inputString.substring(curCharNum, curCharNum + 1));
            chars[curCharNum] = Integer.toString(curDigit).charAt(0);
        }
        if (Character.getType(curChar) == Character.DASH_PUNCTUATION || curChar == 8722)
            chars[curCharNum] = '-';
    }
    String returnString = new String(chars);
    return returnString;
}

From source file:de.tudarmstadt.ukp.dkpro.core.flextag.features.character.ContainsNumber.java

static boolean containsNumber(String aToken) {
    for (char c : aToken.toCharArray()) {
        if (NumberUtils.isDigits("" + c)) {
            return true;
        }//from   w ww. j av a  2 s. c o m
    }
    return false;
}

From source file:Main.java

/**
 * Escape the "special" characters as required for inclusion in XML elements
 * Replaces all incidences of & with & < with < > with > " with " ' with
 * &apos;//from w  w w.  ja v a2  s  .c  om
 * 
 * @param s
 *            The string to scan
 * @return String
 */
public static String escape(String s) {
    char[] array = s.toCharArray();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < array.length; i++) {
        switch (array[i]) {
        case '&':
            sb.append("&amp;");
            break;
        case '<':
            sb.append("&lt;");
            break;
        case '>':
            sb.append("&gt;");
            break;
        case '"':
            sb.append("&quot;");
            break;
        case '\'':
            sb.append("&apos;");
            break;
        default:
            sb.append(array[i]);
        }
    }
    return sb.toString();
}