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 escapeJava(String doco) {
    if (doco == null)
        return "";

    StringBuilder b = new StringBuilder();
    for (char c : doco.toCharArray()) {
        if (c == '\r')
            b.append("\\r");
        else if (c == '\n')
            b.append("\\n");
        else if (c == '"')
            b.append("'");
        else//from w ww  . j av  a 2s  .  c o  m
            b.append(c);
    }
    return b.toString();
}

From source file:com.aestasit.markdown.Markdown.java

public static RootNode toAst(final String text) throws IOException {
    return toAst(text.toCharArray());
}

From source file:com.alu.e3.prov.lifecycle.IDHelper.java

public static String decode(String encoded) {
    try {//  ww w . j  ava2 s.c o  m
        return new String(Hex.decodeHex(encoded.toCharArray()));
    } catch (DecoderException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static String reverse(String s) {
    int len = length(s);
    if (len <= 1)
        return s;
    int mid = len >> 1;
    char[] chars = s.toCharArray();
    char c;// ww w. j a v a2  s  .co m
    for (int i = 0; i < mid; ++i) {
        c = chars[i];
        chars[i] = chars[len - i - 1];
        chars[len - i - 1] = c;
    }
    return new String(chars);
}

From source file:Main.java

/**
 * Encode an attribute value.//from w  w w  .j ava  2s  .com
 * This assumes use of " as the attribute value delimiter.
 * @param str the string to convert.
 * @return the converted string.
 */
public static String escapeAttribute(String str) {
    final StringBuilder b = new StringBuilder();
    final char[] chars = str.toCharArray();
    for (int i = 0; i < chars.length; ++i) {
        final char c = chars[i];
        switch (c) {
        case '<':
            b.append("&lt;");
            break;
        case '>':
            b.append("&gt;");
            break;
        case '&':
            b.append("&amp;");
            break;
        case '"':
            b.append("&quot;");
            break;
        default:
            b.append(c);
        }
    }
    return b.toString();
}

From source file:Main.java

private static final String capitalize(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }/*from  ww w.  j  a va  2  s .com*/
    final char[] arr = str.toCharArray();
    boolean capitalizeNext = true;
    String phrase = "";
    for (final char c : arr) {
        if (capitalizeNext && Character.isLetter(c)) {
            phrase += Character.toUpperCase(c);
            capitalizeNext = false;
            continue;
        } else if (Character.isWhitespace(c)) {
            capitalizeNext = true;
        }
        phrase += c;
    }
    return phrase;
}

From source file:Main.java

private static SecretKey getKeyFromPassphrase(String passphrase, byte[] salt, int iterations)
        throws GeneralSecurityException {
    PBEKeySpec keyspec = new PBEKeySpec(passphrase.toCharArray(), salt, iterations);
    SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWITHSHA1AND128BITAES-CBC-BC");
    return skf.generateSecret(keyspec);
}

From source file:com.autentia.common.util.PasswordUtils.java

private static boolean atLeastOneCapitalLetter(String pwd) {
    final char[] pwdChars = pwd.toCharArray();
    for (int i = 0; i < pwdChars.length; i++) {
        if (Character.isLowerCase(pwdChars[i])) {
            return true;
        }/* ww  w. j  a  va 2s .  c o m*/
    }
    return false;
}

From source file:com.autentia.common.util.PasswordUtils.java

private static boolean atLeastOneLowercaseLetter(String pwd) {
    final char[] pwdChars = pwd.toCharArray();
    for (int i = 0; i < pwdChars.length; i++) {
        if (Character.isUpperCase(pwdChars[i])) {
            return true;
        }/*from  w w w . ja  va  2 s. co m*/
    }
    return false;
}

From source file:com.autentia.common.util.PasswordUtils.java

private static boolean atLeastOneNumber(String pwd) {
    final char[] pwdChars = pwd.toCharArray();
    for (int i = 0; i < pwdChars.length; i++) {
        if (Character.isDigit(pwdChars[i])) {
            return true;
        }/* w  w w . ja va  2s  .  c om*/
    }
    return false;
}