Example usage for java.lang String charAt

List of usage examples for java.lang String charAt

Introduction

In this page you can find the example usage for java.lang String charAt.

Prototype

public char charAt(int index) 

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:Main.java

public static String stripGarbage(String s) {
    String good = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    String result = "";
    for (int i = 0; i < s.length(); i++) {
        if (good.indexOf(s.charAt(i)) >= 0)
            result += s.charAt(i);// w w  w . java 2 s  .c o  m
    }
    return result;
}

From source file:Main.java

static Map<String, Method> getSetPropertyMethods(Class<?> beanClass) {
    HashMap<String, Method> props;
    if (setPropsCache.containsKey(beanClass)) {
        props = setPropsCache.get(beanClass);
    } else {//w w  w .  ja  v a2s  .com
        props = new HashMap<String, Method>();
        setPropsCache.put(beanClass, props);
        Method[] ms = beanClass.getMethods();
        for (int i = 0; i < ms.length; i++) {
            Method m = ms[i];
            String name = m.getName();
            if (name.startsWith("set") && name.length() > 3 && Character.isUpperCase(name.charAt(3))
                    && m.getParameterTypes().length == 1) {
                name = name.substring(3);
                props.put(name, m);
            }
        }
    }
    return props;
}

From source file:Main.java

public static int getStrLength(String content) {
    int length = 0;
    int tempLength = 0;
    for (int i = 0; i < content.length(); i++) {
        String temp = content.charAt(i) + "";
        if (temp.getBytes().length == 3) {
            length++;//from w  w w.  j  a  va 2 s. com
        } else {
            tempLength++;
        }
    }
    length += tempLength / 2 + ((tempLength % 2) == 0 ? 0 : 1);
    return length;
}

From source file:Main.java

/**
 * Convert %XX/*ww w. j a  v a 2  s .  c om*/
 * 
 * @param value
 * @return
 */
public static String formParamDecode(String value) {
    int nCount = 0;
    for (int i = 0; i < value.length(); i++) {
        if (value.charAt(i) == '%') {
            i += 2;
        }
        nCount++;
    }

    byte[] sb = new byte[nCount];

    for (int i = 0, index = 0; i < value.length(); i++) {
        if (value.charAt(i) != '%') {
            sb[index++] = (byte) value.charAt(i);
        } else {
            StringBuilder sChar = new StringBuilder();
            sChar.append(value.charAt(i + 1));
            sChar.append(value.charAt(i + 2));
            sb[index++] = Integer.valueOf(sChar.toString(), 16).byteValue();
            i += 2;
        }
    }
    String decode = "";
    try {
        decode = new String(sb, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return decode;
}

From source file:Main.java

public static String convertHiragana2Katakana(String str) {
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < str.length(); i++) {
        char code = str.charAt(i);
        if ((code >= 0x3041) && (code <= 0x3093)) {
            buf.append((char) (code + 0x60));
        } else {//from  www.  ja va 2  s  .com
            buf.append(code);
        }
    }
    return buf.toString();
}

From source file:Main.java

public static int countLetters(String str) {
    int len = str.length();
    int chars = 0;
    for (int i = 0; i < len; i++) {
        if (Character.isLetter(str.charAt(i)))
            chars++;/*from  w  w w  . ja v a  2s .  c om*/
    }
    return chars;
}

From source file:Main.java

/**
 * Unpad from right. /*from w w w  . j ava 2  s.  c  o m*/
 * @param s - original string
 * @param c - padding char
 * @return unPadded string.
 */
public static String unPadRight(String s, char c) {
    int end = s.length();
    if (end == 0)
        return s;
    while ((0 < end) && (s.charAt(end - 1) == c))
        end--;
    return (0 < end) ? s.substring(0, end) : s.substring(0, 1);
}

From source file:Main.java

static String removeJunk(String string) {
    int i, len = string.length();
    StringBuffer dest = new StringBuffer(len);
    char c;//from  w w w.j a  v a 2  s  .co m

    for (i = (len - 1); i >= 0; i--) {
        c = string.charAt(i);
        if (Character.isLetterOrDigit(c)) {
            dest.append(c);
        }
    }
    return dest.toString();
}

From source file:Main.java

private static boolean isSpace(String s) {
    if (s == null)
        return true;
    for (int i = 0, len = s.length(); i < len; ++i) {
        if (!Character.isWhitespace(s.charAt(i))) {
            return false;
        }// w  w  w  .ja  v  a  2s  .  co  m
    }
    return true;
}

From source file:Main.java

public static String escape(String xmlstr) {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < xmlstr.length(); i++) {
        char c = xmlstr.charAt(i);
        if (c == '&')
            buffer.append("&amp;");
        else if (c == '<')
            buffer.append("&lt;");
        else if (c == '>')
            buffer.append("&gt;");
        else if (c == '"')
            buffer.append("&quot;");
        else if (c == '\'')
            buffer.append("&apos;");
        else/*from  w  w w .  j  ava2s .com*/
            buffer.append(c);
    }
    return buffer.toString();
}