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 isAllWhitespace(String string) {
    if (string == null) {
        return false;
    }/* w  ww  .  j  ava 2 s .c o  m*/
    char[] characters = string.toCharArray();
    for (int i = 0; i < characters.length; i++) {
        if (!Character.isWhitespace(characters[i])) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

public static String MD5(String string) {
    String result = null;/*from   www  .j  a v a  2 s. co  m*/
    try {
        char[] charArray = string.toCharArray();
        byte[] byteArray = new byte[charArray.length];
        for (int i = 0; i < charArray.length; i++) {
            byteArray[i] = (byte) charArray[i];
        }

        StringBuffer hexValue = new StringBuffer();
        byte[] md5Bytes = MessageDigest.getInstance("MD5").digest(byteArray);
        for (int i = 0; i < md5Bytes.length; i++) {
            int val = ((int) md5Bytes[i]) & 0xff;
            if (val < 16) {
                hexValue.append("0");
            }
            hexValue.append(Integer.toHexString(val));
        }

        result = hexValue.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

From source file:com.optimalbi.Services.AmazonService.java

static String stringCap(String text) {
    int maxChars = 99;
    char[] chars = text.toCharArray();
    if (chars.length > 0) {
        chars[0] = Character.toUpperCase(chars[0]);
    } else//  w  w  w .ja va2 s  .  c o m
        return "";
    String shortString = String.valueOf(chars);
    if (shortString.length() > maxChars) {
        shortString = shortString.substring(0, maxChars - 3);
        shortString = shortString + "...";
    }
    return shortString;
}

From source file:Main.java

public static String firstLetterToUpperCase(String name) {
    if (name.trim().length() == 0) {
        return name;
    }// ww  w  .j a  va2 s. co  m
    char c[] = name.toCharArray();
    c[0] = Character.toUpperCase(c[0]);
    name = new String(c);
    return name;
}

From source file:Main.java

public static String capitalize(final String str) {
    if (str.length() == 0) {
        return "";
    }/*from w w  w.  j  av a2  s . co m*/

    final char[] buffer = str.toCharArray();
    buffer[0] = Character.toTitleCase(buffer[0]);

    for (int i = 1; i < buffer.length; i++) {
        if (buffer[i - 1] == ' ') {
            buffer[i] = Character.toTitleCase(buffer[i]);
        }
    }
    return new String(buffer);
}

From source file:Main.java

public static boolean checkDataHexa(String sInput) {
    boolean checkedValue = true;
    sInput = sInput.toUpperCase();/*w w w.j  a v a2s .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') {
            checkedValue = false;
        }
    }
    return checkedValue;
}

From source file:Main.java

/**
 * Returns a variant of the supplied string with all invalid XML name characters
 * removed. A special case is the the space character, which is converted to the '_'
 * character instead.//from ww  w  . j a va  2 s. co m
 * @param name A string that could be used as an XML name.
 * @return A valid XML name equivalent of name.
 */

public static String toValidXMLName(String name) {

    char[] nameAsCharArray = name.toCharArray();
    char[] newNameAsCharArray = new char[nameAsCharArray.length];

    boolean currentCharacterValid = false;
    int j = 0;

    for (int i = 0; i < nameAsCharArray.length; i++) {
        currentCharacterValid = false;

        if (nameAsCharArray[i] == ' ') {
            nameAsCharArray[i] = '_';
        }

        if (Character.isLetterOrDigit(nameAsCharArray[i])) {
            currentCharacterValid = true;
        }

        if (nameAsCharArray[i] == '_' || nameAsCharArray[i] == '-' || nameAsCharArray[i] == '.') {
            currentCharacterValid = true;
        }

        if (currentCharacterValid) {
            newNameAsCharArray[j] = nameAsCharArray[i];
            j++;
        }
    }

    String validElementName = new String(newNameAsCharArray);
    validElementName = validElementName.trim();

    return validElementName;
}

From source file:Main.java

/**
 * Freaking Java trim won't work!!! This is an own implementation of trim.
 * //from ww  w.  ja v  a 2 s.c  o m
 * @return String with all fields separated by ":"
 */
public static String trimmer(String line) {
    String retval = "";
    Boolean series = false;

    for (Character a : line.toCharArray()) {
        if (!a.equals(' ') && !series)
            retval += a;

        if (!a.equals(' ') && series) {
            retval += ":" + a;
            series = false;
        }

        if (a.equals(' ')) {
            series = true;
        }
    }

    return retval;
}

From source file:Main.java

public static String toDBC(String string) {
    if (isEmpty(string)) {
        return string;
    }/*from  w w w. ja  va  2 s . c  o m*/
    char[] chars = string.toCharArray();
    for (int i = 0, len = chars.length; i < len; i++) {
        if (chars[i] == 12288) {
            chars[i] = ' ';
        } else if (65281 <= chars[i] && chars[i] <= 65374) {
            chars[i] = (char) (chars[i] - 65248);
        } else {
            chars[i] = chars[i];
        }
    }
    return new String(chars);
}

From source file:Main.java

public static boolean[] StringToBooleanArray(String bitPattern) {
    boolean[] array = new boolean[bitPattern.length()];
    int index = 0;
    for (char c : bitPattern.toCharArray()) {
        if (c == '0')
            array[index] = false;//from  www. j  a v a2  s.c  o  m
        else
            array[index] = true;
        index++;
    }
    return array;
}