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 int getTrailingWhitespaceStart(String string, int charStart, int charEnd) {
    for (int i = charEnd - 1; i >= charStart; i--) {
        if (!Character.isWhitespace(string.charAt(i))) {
            return i + 1;
        }//w  w w.j  a va  2  s  .com
    }

    return charStart;
}

From source file:StringUtil.java

public static String uncaps(String string) {
    if (string.length() == 0) {
        return string;
    }/*from w  w w  .j av  a  2  s  .c o m*/
    char ch = string.charAt(0);
    if (Character.isUpperCase(ch)) {
        ch = Character.toLowerCase(ch);
        return ch + string.substring(1);
    }
    return string;
}

From source file:StringUtil.java

public static String caps(String string) {
    if (string.length() == 0) {
        return string;
    }//from w  w  w . j  a va 2  s.  c o  m
    char ch = string.charAt(0);
    if (Character.isLowerCase(ch)) {
        ch = Character.toUpperCase(ch);
        return ch + string.substring(1);
    }
    return string;
}

From source file:io.rhiot.utils.Reflections.java

public static String classNameToCamelCase(Class<?> clazz) {
    String simpleName = clazz.getSimpleName();
    return toLowerCase(simpleName.charAt(0)) + simpleName.substring(1);
}

From source file:Main.java

/**
 * Indicates if the given MIME type is related to XML or not.
 * <p>/*w  w w. j a  va2s.co  m*/
 * XML MIME types :
 * </p>
 * <ul>
 * <li>"<tt>text/xml</tt>",</li>
 * <li>"<tt>application/xml</tt>",</li>
 * <li>"<tt>image/svg+xml</tt>",</li>
 * <li>etc</li>
 * </ul>
 * <p>
 * Non-XML MIME types :
 * </p>
 * <ul>
 * <li>"<tt>application/xml-dtd</tt>",</li>
 * <li>"<tt>application/xml-external-parsed-entity</tt>",</li>
 * <li>etc</li>
 * </ul>
 *
 * @param mimeType
 *            The MIME type to test.
 * @return <code>true</code> if the MIME type contains the string "xml" not
 *         followed by "-", <code>false</code> otherwise.
 */
public static boolean isXMLMimeType(String mimeType) {
    int index = mimeType.indexOf("xml");
    if (index != -1 && (index + 3 < mimeType.length()) ? mimeType.charAt(index + 3) != '-' : true) {
        // "application/xml", "text/xml", "image/svg+xml",
        // "application/xhtml+xml", etc
        // but not "application/xml-dtd",
        // "application/xml-external-parsed-entity" etc
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

private static void writeEsc(Writer w, String s, boolean isAttVal) throws IOException {
    for (int i = 0; i < s.length(); i++) {
        switch (s.charAt(i)) {
        case '&':
            w.write("&amp;");
            break;
        case '<':
            w.write("&lt;");
            break;
        case '>':
            w.write("&gt;");
            break;
        case '\"':
            if (isAttVal) {
                w.write("&quot;");
            } else {
                w.write('\"');
            }/*from   w ww  .j  a  va 2 s . c o  m*/
            break;
        default:
            w.write(s.charAt(i));
        }
    }
}

From source file:Main.java

public static String fixApplicationId(final String appId) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < appId.length(); i++) {
        final char ch = appId.charAt(i);
        if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == '-'
                || ch == '.') {
            builder.append(ch);//  w  w  w.  j  a  v  a2 s. c o  m
        }
    }
    return builder.toString();
}

From source file:com.moz.fiji.schema.util.JavaIdentifiers.java

/**
 * Determines whether a string is a valid Java identifier.
 *
 * <p>A valid Java identifier may not start with a number, but may contain any
 * combination of letters, digits, underscores, or dollar signs.</p>
 *
 * <p>See the <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.8">
 * Java Language Specification</a></p>
 *
 * @param identifier The identifier to test for validity.
 * @return Whether the identifier was valid.
 *//*from   ww w.  j  ava 2s  .  c  om*/
public static boolean isValidIdentifier(String identifier) {
    if (identifier.isEmpty() || !Character.isJavaIdentifierStart(identifier.charAt(0))) {
        return false;
    }
    for (int i = 1; i < identifier.length(); i++) {
        if (!Character.isJavaIdentifierPart(identifier.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

public static boolean isOptionSet(String s, int pos) {
    if (s == null || pos < 0 || pos >= s.length()) {
        return false; // out of range == not set
    }//from   w  ww .  ja  v  a  2s .  c o  m
    return s.charAt(pos) == '+';
}

From source file:Main.java

/**
 * Tell whether the string contains an unsigned number.
 *//*www .  j  av a2s  .  c om*/
public static boolean isUnsignedNumber(String string) {
    String s = string.trim();
    if (s.length() < 1)
        return false;
    if (s.charAt(0) != '+' && s.charAt(0) != '-') {
        double value = 0;
        try {
            value = Double.parseDouble(s);
        } catch (NumberFormatException e) {
            return false;
        }
        return true;
    }
    return false;
}