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 void escapedAdd(final StringBuilder sb, final String str) {
    for (int i = 0; i < str.length(); i++) {
        final char ch = str.charAt(i);
        if (ch < 33 || Character.isWhitespace(ch) || Character.isSpaceChar(ch)) {
            sb.append(' ');
        } else {/*from  w ww  . j  a  va 2 s  .  c  om*/
            switch (ch) {
            case '"':
                sb.append("&quot;");
                break;
            case '\'':
                sb.append("&apos;");
                break;
            case '<':
                sb.append("&lt;");
                break;
            case '>':
                sb.append("&gt;");
                break;
            case '&':
                sb.append("&amp;");
                break;
            default:
                sb.append(ch);
                break;
            }
        }
    }
}

From source file:de.dfki.resc28.ole.bootstrap.Util.java

public static String appendSegmentToPath(String path, String segment) {
    boolean segmentStartsWithSlash = !segment.isEmpty() && segment.charAt(0) == '/';

    if (path == null || path.isEmpty()) {
        return segmentStartsWithSlash ? segment : "/" + segment;
    }//from   www  .j a v a 2s .  c  om

    if (path.charAt(path.length() - 1) == '/') {
        return segmentStartsWithSlash ? path + segment.substring(1) : path + segment;
    }

    return segmentStartsWithSlash ? path + segment : path + "/" + segment;
}

From source file:Main.java

public static int delimiterOffset(String input, int pos, int limit, String delimiters) {
    for (int i = pos; i < limit; i++) {
        if (delimiters.indexOf(input.charAt(i)) != -1)
            return i;
    }/*from  w  ww .j  a  v a2s .co  m*/
    return limit;
}

From source file:Main.java

static String toDbColumName(String name) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0, size = name.length(); i < size; i++) {
        char c = name.charAt(i);
        if (c >= 'A' && c <= 'Z') {
            sb.append("_" + Character.toLowerCase(c));
        } else {/*from   www  .  j a  v  a 2  s.  com*/
            sb.append(c);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static void writeXML(PrintWriter out, String str) {
    for (int i = 0; i < str.length(); i++) {
        char ch = str.charAt(i);

        switch (ch) {
        case '<':
            out.write("&lt;");
            break;

        case '>':
            out.write("&gt;");
            break;

        case '&':
            out.write("&amp;");
            break;

        case '"':
            out.write("&quot;");
            break;

        case '\'':
            out.write("&apos;");
            break;

        case '\r':
        case '\n':
            out.write(ch);//from ww  w  .j a  v  a 2 s.  c o  m
            break;

        default:
            if ((ch < 32) || (ch > 126)) {
                out.write("&#x");
                out.write(Integer.toString(ch, 16));
                out.write(';');
            } else {
                out.write(ch);
            }
            break;
        }
    }
}

From source file:StringUtil.java

/**
 * @return the string provided with its first character capitalized
 *//*from w w w  . j  a  v  a  2 s .c o m*/
public static String capitalize(String s) {
    if (s.length() == 0) {
        return s;
    }
    char first = s.charAt(0);
    char capitalized = Character.toUpperCase(first);
    return (first == capitalized) ? s : capitalized + s.substring(1);
}

From source file:Main.java

public static String clearMonthDate(String word) {
    String result = "";
    for (int i = 0; i < word.length(); i++) {
        if (TextUtils.isDigitsOnly(Character.toString(word.charAt(i)))) {
            result += Character.toString(word.charAt(i));
        }/*from ww  w .  j ava 2  s  .co m*/
    }
    return result;
}

From source file:Main.java

public static int countChars(String term, char mychar) {
    int l = term.length();
    int counter = 0;
    for (int i = 0; i < l; i++) {
        if (term.charAt(i) == mychar)
            counter++;//from  w w w .  j a  va 2s . c o m
    }
    return counter;
}

From source file:Main.java

public static boolean isXMLName(String text) {
    if (text == null || text.length() <= 0)
        return false;
    if (!Character.isLetter(text.charAt(0)))
        return false;
    for (int i = 0; i < text.length(); i++) {
        char ch = text.charAt(i);
        if (Character.isLetter(ch))
            continue;
        if (Character.isDigit(ch))
            continue;
        if (ch == '.' || ch == ':' || ch == '_' || ch == '-')
            continue;
        return false;
    }/*from   w  w w.  j a  v a  2  s. co m*/
    return true;
}

From source file:Main.java

public static int skipTrailingAsciiWhitespace(String input, int pos, int limit) {
    for (int i = limit - 1; i >= pos; i--) {
        switch (input.charAt(i)) {
        case '\t':
        case '\n':
        case '\f':
        case '\r':
        case ' ':
            continue;
        default://from   www.  j  av  a  2s  . co  m
            return i + 1;
        }
    }
    return pos;
}