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:cc.vidr.datum.term.StringTerm.java

/**
 * Create a new StringTerm for the given string literal. Surrounding quotes
 * will be removed and escaped characters unescaped.
 * /*  w  w w  .j a v a 2 s. c om*/
 * @param string  the string literal
 * @return        the StringTerm
 */
public static StringTerm parse(String string) {
    if (string.charAt(0) == '"') // remove quotes
        string = string.substring(1, string.length() - 1);
    return new StringTerm(StringEscapeUtils.unescapeJava(string));
}

From source file:Main.java

/**
 * Remove/collapse multiple newline characters.
 *
 * @param argStr string to collapse newlines in.
 * @return String//from  w w  w.  j  a v a 2 s  . co m
 */
public static String collapseNewlines(String argStr) {
    char last = argStr.charAt(0);
    StringBuffer argBuf = new StringBuffer();

    for (int cIdx = 0; cIdx < argStr.length(); cIdx++) {
        char ch = argStr.charAt(cIdx);
        if (ch != '\n' || last != '\n') {
            argBuf.append(ch);
            last = ch;
        }
    }

    return argBuf.toString();
}

From source file:Main.java

/**
 * Remove/collapse multiple spaces./*from ww w .j  a  va2 s.co  m*/
 *
 * @param argStr string to remove multiple spaces from.
 * @return String
 */
public static String collapseSpaces(String argStr) {
    char last = argStr.charAt(0);
    StringBuffer argBuf = new StringBuffer();

    for (int cIdx = 0; cIdx < argStr.length(); cIdx++) {
        char ch = argStr.charAt(cIdx);
        if (ch != ' ' || last != ' ') {
            argBuf.append(ch);
            last = ch;
        }
    }

    return argBuf.toString();
}

From source file:Main.java

private static boolean isAlphaNum(String s) {
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (!('0' <= c && c <= '9') && !('A' <= c && c <= 'Z') && " $%*+-./:".indexOf(c) == -1) {
            return false;
        }// www .jav  a 2s . c  om
    }
    return true;
}

From source file:Main.java

private static boolean isNumber(String s) {
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (!('0' <= c && c <= '9')) {
            return false;
        }//from ww w  .  j a  v  a  2  s.  c  om
    }
    return true;
}

From source file:info.mikaelsvensson.devtools.common.PathUtils.java

public static String trailingSlash(String str) {
    if (str.charAt(str.length() - 1) != SEP) {
        return str + SEP;
    }/*from   w w w . j a  v a 2  s . c om*/
    return str;
}

From source file:Main.java

private static boolean whitespaceOnly(String s) {
    for (int i = 0; i < s.length(); i++) {
        char cur = s.charAt(i);
        if (cur != ' ' && cur != '\n' && cur != '\r') {
            return false;
        }//from   ww w. j  a v a2  s  .c o  m
    }
    return true;
}

From source file:Main.java

public static String capitalize(final String word) {
    if (word.length() > 1) {
        return String.valueOf(word.charAt(0)).toUpperCase() + word.substring(1);
    }/* w  ww  .  j  av a 2 s  .c o m*/
    return word;
}

From source file:Main.java

/**
 * Parses href and obtains plugin id//  w  ww .  j  a  v  a2s. c o  m
 * 
 * @param href
 *            String in format /string1[/string2]
 * @return plugin ID, or null
 */
public static String getPluginIDFromHref(String href) {
    if (href == null || href.length() < 2 || href.charAt(0) != '/')
        return null;
    int secondSlashIx = href.indexOf("/", 1); //$NON-NLS-1$
    if (secondSlashIx < 0) // href is /pluginID
        return href.substring(1);
    // href is /pluginID/path[#anchorID]
    return href.substring(1, secondSlashIx);
}

From source file:Main.java

private static int iAt(String s, int index) {
    if (index < s.length()) {
        return (((int) s.charAt(index)) & 0xff);
    } else {//from  w ww .  ja  v a  2s  .c o  m
        return -1;
    }

}