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 List<String> listDesc(String desc) {
    List<String> list = new ArrayList<String>(5);
    char[] chars = desc.toCharArray();
    int i = 0;//ww w . ja  va2s. c om
    while (i < chars.length) {
        switch (chars[i]) {
        case 'V':
        case 'Z':
        case 'C':
        case 'B':
        case 'S':
        case 'I':
        case 'F':
        case 'J':
        case 'D':
            list.add(Character.toString(chars[i]));
            i++;
            break;
        case '[': {
            int count = 1;
            while (chars[i + count] == '[') {
                count++;
            }
            if (chars[i + count] == 'L') {
                count++;
                while (chars[i + count] != ';') {
                    count++;
                }
            }
            count++;
            list.add(new String(chars, i, count));
            i += count + 1;
            break;
        }
        case 'L': {
            int count = 1;
            while (chars[i + count] != ';') {
                ++count;
            }
            count++;
            list.add(new String(chars, i, count));
            i += count + 1;
            break;
        }
        default:
        }
    }
    return list;
}

From source file:Main.java

public static String ByteToString(byte[] byteArray) {
    if (byteArray == null) {
        return null;
    }/*from  www  . j  a  v  a  2s  . c  om*/
    try {
        String result = new String(byteArray, "ASCII");
        result = String.copyValueOf(result.toCharArray(), 0, byteArray.length);
        return result;
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:Main.java

public static boolean containsInvalidXMLCharacter(@Nullable final String s) {
    return s != null && containsInvalidXMLCharacter(s.toCharArray());
}

From source file:Main.java

/**
 * Replace the not support emoji.//from w  w w . ja v a  2s  .co m
 * @param str
 * @return
 */
public static String matchEmojiUnicode(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }
    char[] charArray = str.toCharArray();
    try {
        for (int i = 0; i < charArray.length - 1; i++) {
            int _index = charArray[i];
            int _index_inc = charArray[i + 1];

            if (_index == 55356) {
                if ((_index_inc < 56324) || (_index_inc > 57320)) {
                    continue;
                }
                charArray[i] = '.';
                charArray[(i + 1)] = '.';
                continue;
            }

            if ((_index != 55357) || (_index_inc < 56343) || (_index_inc > 57024)) {
                continue;
            }

            charArray[i] = '.';
            charArray[(i + 1)] = '.';
        }
    } catch (Exception e) {
    }

    return new String(charArray);
}

From source file:com.amazonaws.cognito.devauthsample.AESEncryption.java

private static SecretKeySpec getKey(String key) {
    try {// w  w  w.  j  a v a2s .  com
        return new SecretKeySpec(Hex.decodeHex(key.toCharArray()), "AES");
    } catch (DecoderException e) {
        throw new RuntimeException("Failed to generate a secret key spec", e);
    }
}

From source file:Main.java

public static String substring(String str, int toCount, String more) {
    int reInt = 0;
    String reStr = "";
    if (str == null)
        return "";
    char[] tempChar = str.toCharArray();
    for (int kk = 0; (kk < tempChar.length && toCount > reInt); kk++) {
        String s1 = String.valueOf(tempChar[kk]);
        byte[] b = s1.getBytes();
        reInt += b.length;//from  ww  w . j a v  a2 s. c  o  m
        reStr += tempChar[kk];
    }
    if (toCount == reInt || (toCount == reInt - 1))
        reStr += more;
    return reStr;
}

From source file:GitHubApiTest.java

private static String rewind(String s) {
    StringBuilder sb = new StringBuilder();
    for (char c : s.toCharArray()) {
        sb.insert(0, c);/*from  w w  w  . j a v a2  s.  com*/
    }
    return sb.toString();
}

From source file:com.opengamma.integration.viewer.status.AggregateType.java

private static boolean hasInvalidCharacter(String aggregationOptionType) {
    char[] aggregateTypeChars = aggregationOptionType.toCharArray();
    for (char character : aggregateTypeChars) {
        if (!VALID_AGGRAGATION_CHARS.contains(character)) {
            return true;
        }//from w  w  w.  j a  va  2s .c  om
    }
    return false;
}

From source file:apm.common.utils.Encodes.java

/**
 * Hex?./*  w  ww  .  j  a  v  a2 s  .  c  om*/
 */
public static byte[] decodeHex(String input) {
    try {
        return Hex.decodeHex(input.toCharArray());
    } catch (DecoderException e) {
        throw Exceptions.unchecked(e);
    }
}

From source file:com.assemblade.opendj.acis.Subject.java

public static Subject parse(String rule) {
    if (StringUtils.isNotEmpty(rule)) {
        rule = rule.trim();//from  w w  w. java  2s .  c  o  m
        char[] ruleArray = rule.toCharArray();

        if (rule.startsWith("(")) {
            int brackets = 0;

            for (int position = 0; position < ruleArray.length; position++) {
                if (ruleArray[position] == '(') {
                    brackets++;
                } else if (ruleArray[position] == ')') {
                    brackets--;
                }
                if (brackets == 0) {
                    Subject subject = Subject.parse(rule.substring(1, position));
                    if (position < (ruleArray.length - 1)) {
                        return CompositeSubject.parse(subject, rule.substring(position + 1));
                    }
                    return subject;
                }
            }
        } else {
            return PermissionSubject.parse(rule);
        }
    }
    return null;
}