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 boolean isBlank(String s) {
    boolean result = true;

    if (s != null) {
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != ' ') {
                result = false;/*from ww w.ja va  2  s  .c om*/
                break;
            }
        }
    }

    return result;
}

From source file:Main.java

private static String getDigitsOnly(String s) {
    StringBuffer digitsOnly = new StringBuffer();
    char c;//from   w  w w.j  a  va2 s  .  c  o  m
    for (int i = 0; i < s.length(); i++) {
        c = s.charAt(i);
        if (Character.isDigit(c)) {
            digitsOnly.append(c);
        }
    }
    return digitsOnly.toString();
}

From source file:Main.java

public static String toZenkanaCase(String str) {
    StringBuilder buffer = new StringBuilder(str);

    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (H2Z.containsKey(c)) {
            buffer.setCharAt(i, H2Z.get(c));
        }//from  ww w  .j  av a2  s  . co  m
    }

    return buffer.toString();
}

From source file:Main.java

public static String escape(String str) {
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        String escaped = HTML_ESCAPE_CHARACTERS.get(c);
        if (escaped == null) {
            result.append(c);//from w w  w  .j a v  a  2 s  .  co  m
        } else {
            result.append(escaped);
        }
    }
    return result.toString();
}

From source file:Main.java

public static String tagNameToFieldName(String tagName) {
    int minusIndex = tagName.indexOf('-');
    while (minusIndex != -1) {
        char nextChar = tagName.charAt(minusIndex + 1);
        char upper = Character.toUpperCase(nextChar);
        StringBuilder sb = new StringBuilder(tagName);
        sb.replace(minusIndex + 1, minusIndex + 2, new String(new char[] { upper }));
        sb.replace(minusIndex, minusIndex + 1, "");
        tagName = sb.toString();/*from   w w w. j ava2s  .  c  om*/
        minusIndex = tagName.indexOf('-');
    }
    return tagName;
}

From source file:Main.java

/**
 * INTERIM:  From newer version of org.apache.james (but we don't want to import
 * the entire MimeUtil class).//  www . ja  va  2  s . com
 *
 * Search for whitespace.
 */
private static int indexOfWsp(String s, int fromIndex) {
    final int len = s.length();
    for (int index = fromIndex; index < len; index++) {
        char c = s.charAt(index);
        if (c == ' ' || c == '\t')
            return index;
    }
    return len;
}

From source file:com.twitter.common.logging.LogUtil.java

/**
 * Expands a directory path wildcard within a file pattern string.
 * Correctly handles cases where the replacement string does and does not contain a trailing
 * slash.//from  w ww.j  a  va2  s.c o m
 *
 * @param pattern File pattern string, which may or may not contain a wildcard.
 * @param dirWildcard Wildcard string to expand.
 * @param replacement Path component to expand wildcard to.
 * @return {@code pattern} with all instances of {@code dirWildcard} replaced with
 *     {@code replacement}.
 */
private static String expandWildcard(String pattern, String dirWildcard, String replacement) {
    String replace = dirWildcard;
    if (replacement.charAt(replacement.length() - 1) == '/') {
        replace += '/';
    }
    return pattern.replaceAll(replace, replacement);
}

From source file:Main.java

/**
 * Given a file name in the current working directory,
 * complete it and turn it into a URL.//  w w  w.  j  a  v a2  s.c o m
 */
public static final String makeAbsoluteURL(String url) throws MalformedURLException {
    URL baseURL;
    System.out.println("orig url: " + url);

    String currentDirectory = System.getProperty("user.dir");

    String fileSep = System.getProperty("file.separator");
    String file = currentDirectory.replace(fileSep.charAt(0), '/') + '/';

    if (file.charAt(0) != '/') {
        file = "/" + file;
    }

    System.out.println("new url: " + file);
    baseURL = new URL("file", null, file);
    return new URL(baseURL, url).toString();
}

From source file:Main.java

public static int javaDefaultHash(String str) {
    int h = 0;/*  w w w .j  a  v a 2 s . c  o m*/
    int off = 0;
    int len = str.length();
    for (int i = 0; i < len; i++) {
        h = 31 * h + str.charAt(off++);
    }
    return h;
}

From source file:Main.java

public static int getLeadingWhitespaceEnd(String string, int charStart, int charEnd) {
    for (int i = charStart; i < charEnd; i++) {
        if (!Character.isWhitespace(string.charAt(i))) {
            return i;
        }/* ww  w  .  ja  v  a 2 s . co m*/
    }

    return charEnd;
}