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 long getRunningProcess() {

    File file = new File("/proc/meminfo");
    BufferedReader bufferedReader = null;
    String total = null;//from   w w w .j  a  v  a 2s  .  co m
    try {
        bufferedReader = new BufferedReader(new FileReader(file));
        String line = bufferedReader.readLine();
        char[] charArray = line.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < charArray.length; i++) {
            char c = charArray[i];
            if (c >= '0' && c <= '9') {
                sb.append(c);
            }
        }
        total = sb.toString();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    long number = Long.parseLong(total) * 1024;
    return number;
}

From source file:Main.java

public static String toLowerCase(String strSrc) {
    if (TextUtils.isEmpty(strSrc)) {
        return strSrc;
    }/*from www  .ja v  a 2s .  c  om*/
    char[] chars = strSrc.toCharArray();
    if (chars == null) {
        return strSrc;
    }
    for (int i = 0; i < chars.length; i++) {
        char c = chars[i];
        if ('A' <= c && c <= 'Z') {
            chars[i] = (char) (c + 'a' - 'A');
        }
    }
    return String.valueOf(chars);
}

From source file:Main.java

/**
 * Return a valid element name from the given string.
 *
 * <p>Letters are put to lower case and other characters are replaced by hyphens.
 * If the first character is not a letter it is replaced by 'x'.
 *
 * @param name The candidate element name
 *
 * @return A valid element name/*from  ww  w  . j av a 2 s.c  om*/
 */
public static String toElementName(String name) {
    if (name == null)
        return null;
    char[] elementAsChars = name.toCharArray();
    if (!Character.isLetter(elementAsChars[0])) {
        elementAsChars[0] = 'x';
    } else {
        elementAsChars[0] = Character.toLowerCase(elementAsChars[0]);
    }
    for (int i = 1; i < elementAsChars.length; i++) {
        if (!Character.isLetter(elementAsChars[i])) {
            elementAsChars[i] = '-';
        } else {
            elementAsChars[i] = Character.toLowerCase(elementAsChars[i]);
        }
    }
    return new String(elementAsChars);
}

From source file:Main.java

public static String FormatBarCode(String barCode) {
    if (barCode.length() == 13) {
        Log.i("msg", "barcodeLength==13");
        char[] temp = barCode.toCharArray();
        return temp[0] + " " + temp[1] + temp[2] + temp[3] + temp[4] + temp[5] + temp[6] + " " + temp[7]
                + temp[8] + temp[9] + temp[10] + temp[11] + temp[12];
    }//w  w w. j  a  v a2 s . c o m
    Log.i("msg", "barcodeLength!=13");
    return barCode;
}

From source file:Main.java

public static byte hexStringToByte(String hex) {
    byte result;/* w  ww.ja  v a2s . co  m*/
    if (hex.length() == 1) {
        hex = "0" + hex;
    }
    char[] achar = hex.toCharArray();
    result = (byte) (toByte(achar[0]) << 4 | toByte(achar[1]));
    return result;
}

From source file:Main.java

/**
 * decode Unicode string/*from   ww w. j  a va 2s  .  c o  m*/
 *
 * @param s s
 * @return string
 */
public static String decodeUnicodeStr(String s) {
    StringBuilder sb = new StringBuilder(s.length());
    char[] chars = s.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        char c = chars[i];
        if (c == '\\' && chars[i + 1] == 'u') {
            char cc = 0;
            for (int j = 0; j < 4; j++) {
                char ch = Character.toLowerCase(chars[i + 2 + j]);
                if ('0' <= ch && ch <= '9' || 'a' <= ch && ch <= 'f') {
                    cc |= (Character.digit(ch, 16) << (3 - j) * 4);
                } else {
                    cc = 0;
                    break;
                }
            }
            if (cc > 0) {
                i += 5;
                sb.append(cc);
                continue;
            }
        }
        sb.append(c);
    }
    return sb.toString();
}

From source file:Main.java

public static byte[] hexStringToByte(String aMessage) {
    int i = aMessage.length() / 2;
    byte[] arrayOfByte = new byte[i];
    char[] arrayOfChar = aMessage.toCharArray();
    for (int j = 0; j < i; j++) {
        int k = j * 2;
        arrayOfByte[j] = ((byte) (toByte(arrayOfChar[k]) << 4 | toByte(arrayOfChar[(k + 1)])));
    }//from ww  w  . j  av  a  2s .  c o  m
    return arrayOfByte;
}

From source file:ASCII2NATIVE.java

/**    
 * Native to ascii string. It's same as execut native2ascii.exe.    
 *     //from   w ww .j  a v  a  2  s . c  om
 * @param str    
 *            native string    
 * @return ascii string    
 */
public static String native2Ascii(String str) {
    char[] chars = str.toCharArray();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < chars.length; i++) {
        sb.append(char2Ascii(chars[i]));
    }
    return sb.toString();
}

From source file:Main.java

/**
 * get total size of ram. Work for all API levels.
 * @return total size in byte/*w  w  w .  j av a  2 s.  c o  m*/
 * @deprecated
 */
public static long getTotalRamSize() {
    StringBuilder sb = new StringBuilder();
    //read this file and pick up numbers
    File file = new File("/proc/meminfo");
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(file));
        String readLine = br.readLine();
        char[] charArray = readLine.toCharArray();
        for (char c : charArray) {
            if (c >= '0' && c <= '9') {
                sb.append(c);
            }
        }
        String string = sb.toString();
        long parseLong = Long.parseLong(string);
        return parseLong * 1024;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return 0;
}

From source file:Main.java

public static String checkAndChangeDataHexa(String sInput) {
    String CheckedAndChangedValue = "";
    sInput = sInput.toUpperCase();/*from ww  w .  j ava2 s.  c o  m*/
    char[] cInput = sInput.toCharArray();

    for (int i = 0; i < sInput.length(); i++) {
        if (cInput[i] == '0' || cInput[i] == '1' || cInput[i] == '2' || cInput[i] == '3' || cInput[i] == '4'
                || cInput[i] == '5' || cInput[i] == '6' || cInput[i] == '7' || cInput[i] == '8'
                || cInput[i] == '9' || cInput[i] == 'A' || cInput[i] == 'B' || cInput[i] == 'C'
                || cInput[i] == 'D' || cInput[i] == 'E' || cInput[i] == 'F') {
            CheckedAndChangedValue += cInput[i];
        }
    }
    return CheckedAndChangedValue;
}