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 upperFirstLetter(String s) {
    if (isEmpty(s) || !Character.isLowerCase(s.charAt(0)))
        return s;
    return String.valueOf((char) (s.charAt(0) - 32)) + s.substring(1);
}

From source file:Main.java

public static OutputStream readFromFile(String path, String fileName) {
    if (path.charAt(path.length() - 1) != '/') {
        path += '/';
    }// w  w w. j av a2s  . com

    File file = new File(path + fileName);
    OutputStream os = null;
    try {
        os = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return os;
}

From source file:Main.java

public static String capitalize(String propertyName) {
    return Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
}

From source file:Main.java

/**
 * Removes the first character from the supplied string if this is a plus sign ('+'). Number strings with
 * leading plus signs cannot be parsed by methods such as {@link Integer#parseInt(String)}.
 *//*from w  ww .  j  av a 2  s.c  o  m*/
private static String trimPlusSign(String s) {
    if (s.length() > 0 && s.charAt(0) == '+') {
        return s.substring(1);
    } else {
        return s;
    }
}

From source file:Main.java

static String capitalize(final String word) {
    return Character.toUpperCase(word.charAt(0)) + word.substring(1);
}

From source file:Main.java

public static Node evalSimpleXPathOnDom(String xpath, Node node) {
    if (xpath.charAt(0) != '/') {
        throw new RuntimeException("Not Implemented!");
    }/*  w  w w . j a  va2s  .  co  m*/
    String[] tags = xpath.substring(1).split("/");
    for (int i = 0; i < tags.length; i++) {
        String tag = tags[i];
        node = selectNode(node, tag);
        if (node == null) {
            return null;
        }
    }
    return node;
}

From source file:Main.java

public static String trimStringValue(String value) {
    if (value == null) {
        return null;
    }// w w w . j a v a  2  s . c om
    String text = value;
    char initialChar = text.charAt(0);
    if (text.charAt(text.length() - 1) != initialChar) {
        throw new IllegalArgumentException("malformed string literal");
    }
    text = text.substring(1, text.length() - 1);
    if (initialChar == '\'') {
        text = text.replace("''", "'");
    } else if (initialChar == '"') {
        text = text.replace("\"\"", "\"");
    } else {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    return text;
}

From source file:Main.java

public static String decode(String entity) {
    if (entity.charAt(entity.length() - 1) == ';') // remove trailing
        // semicolon
        entity = entity.substring(0, entity.length() - 1);
    if (entity.charAt(1) == '#') {
        int start = 2;
        int radix = 10;
        if (entity.charAt(2) == 'X' || entity.charAt(2) == 'x') {
            start++;/*from  w w  w  .j  ava  2 s . co  m*/
            radix = 16;
        }
        Character c = new Character((char) Integer.parseInt(entity.substring(start), radix));
        return c.toString();
    } else {
        String s = decoder.get(entity);

        if (s != null)
            return s;
        else
            return "";
    }
}

From source file:Main.java

private static int getEndIndex(String term) {
    int index = term.length() - 1;
    while (term.charAt(index) == '*') {
        --index;// w  w  w .  j  a v  a 2s .c  om
        if (index < 0) {
            break;
        }
    }
    return index;
}

From source file:Main.java

/**
 * parse value to char/*from  w w  w .j a  va  2  s . co  m*/
 */
public static char toChar(String value) {
    return TextUtils.isEmpty(value) ? '\0' : value.charAt(0);
}