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 prefixWithSeparator(final String s) {
    if (s != null && s.length() > 0) {
        char firstCharacter = s.charAt(0);
        if (firstCharacter != '\\' && firstCharacter != '/') {
            return File.separatorChar + s;
        }/*from  w w w  . ja  v a2s . c  o  m*/
    }
    return s;
}

From source file:Main.java

public static String toCamelCase(String tag) {
    String camel = "";
    for (int j = 0; j < tag.length(); j++) {
        char ch = tag.charAt(j);
        if (j == 0) {
            camel += Character.toUpperCase(ch);
        } else if (ch == '-') {
            camel += Character.toUpperCase(tag.charAt(j + 1));
            j++;/*from w ww .  java 2  s  .co m*/
        } else {
            camel += ch;
        }
    }
    return camel;
}

From source file:Utils.java

public final static String removeChar(String str, char c) {
    String output = new String();
    for (int i = 0; i < str.length(); i++) {
        if (str.charAt(i) != c)
            output += str.charAt(i);// w w  w.  j  a  va2 s . c  om
    }
    return output;
}

From source file:Util.java

/**
* Returns a string that is equivalent to the specified string with its
* first character converted to uppercase as by {@link String#toUpperCase}.
* The returned string will have the same value as the specified string if
* its first character is non-alphabetic, if its first character is already
* uppercase, or if the specified string is of length 0.
*
* <p>For example://from w ww . ja v a2  s .  c  o m
* <pre>
*    capitalize("foo bar").equals("Foo bar");
*    capitalize("2b or not 2b").equals("2b or not 2b")
*    capitalize("Foo bar").equals("Foo bar");
*    capitalize("").equals("");
* </pre>
*
* @param s the string whose first character is to be uppercased
* @return a string equivalent to <tt>s</tt> with its first character
*     converted to uppercase
* @throws NullPointerException if <tt>s</tt> is null
*/
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:com.intuit.tank.vm.common.util.ValidationUtil.java

private static final String removeIdentifier(String key, char c) {
    if (key.charAt(0) == c) {
        key = key.replaceFirst(Character.toString(c), "");
    }//from ww w.j  a  v a 2s  . com
    return key;
}

From source file:Main.java

public static String markerIconURL(String accessToken, String size, String symbol, String color) {
    // Make a string which follows the Mapbox Core API spec for stand-alone markers. This relies on the Mapbox API
    // for error checking.

    StringBuffer marker = new StringBuffer("pin-");
    final String lowerCaseSize = size.toLowerCase(Locale.US);

    if (lowerCaseSize.charAt(0) == 'l') {
        marker.append("l"); // large
    } else if (lowerCaseSize.charAt(0) == 's') {
        marker.append("s"); // small
    } else {/*  w  w w.java2  s  .  c  o m*/
        marker.append("m"); // default to medium
    }

    if (!TextUtils.isEmpty(symbol)) {
        marker.append(String.format("-%s+", symbol));
    } else {
        marker.append("+");
    }

    marker.append(color.replaceAll("#", ""));

    //        if (AppUtils.isRunningOn2xOrGreaterScreen(context)) {
    //            marker.append("@2x");
    //        }
    marker.append(".png");

    marker.append("?access_token=");
    marker.append(accessToken);
    return String.format(Locale.US, MAPBOX_BASE_URL_V4 + "marker/%s", marker);
}

From source file:Main.java

public static int getStringAllLength(String str) {
    int len = 0;/*from   w w w .  j a  va  2 s  .c  o m*/
    for (int i = 0; i < str.length(); i++) {
        if (isChineseChars(str.charAt(i))) {
            len += 2;
        } else {
            len++;
        }
    }
    return len;
}

From source file:StringUtil.java

/**
 * returns the next index of a character from the chars string
 *///from  w ww .  j a  v a2  s . c  o m
public static int indexFrom(String s, String chars) {
    for (int i = 0; i < s.length(); i++)
        if (chars.indexOf(s.charAt(i)) >= 0)
            return i;
    return -1;
}

From source file:Main.java

public static void unzip(InputStream is, String dir) throws IOException {
    File dest = new File(dir);
    if (!dest.exists()) {
        dest.mkdirs();//from  ww  w  .  j  av  a2  s .c o m
    }

    if (!dest.isDirectory())
        throw new IOException("Invalid Unzip destination " + dest);
    if (null == is) {
        throw new IOException("InputStream is null");
    }

    ZipInputStream zip = new ZipInputStream(is);

    ZipEntry ze;
    while ((ze = zip.getNextEntry()) != null) {
        final String path = dest.getAbsolutePath() + File.separator + ze.getName();

        String zeName = ze.getName();
        char cTail = zeName.charAt(zeName.length() - 1);
        if (cTail == File.separatorChar) {
            File file = new File(path);
            if (!file.exists()) {
                if (!file.mkdirs()) {
                    throw new IOException("Unable to create folder " + file);
                }
            }
            continue;
        }

        FileOutputStream fout = new FileOutputStream(path);
        byte[] bytes = new byte[1024];
        int c;
        while ((c = zip.read(bytes)) != -1) {
            fout.write(bytes, 0, c);
        }
        zip.closeEntry();
        fout.close();
    }
}

From source file:Main.java

public static Pattern compilePattern(String key, boolean ignoreCase) {
    StringTokenizer stk = new StringTokenizer(key, "*?", true);
    StringBuilder regex = new StringBuilder();
    while (stk.hasMoreTokens()) {
        String tk = stk.nextToken();
        char ch1 = tk.charAt(0);
        if (ch1 == '*') {
            regex.append(".*");
        } else if (ch1 == '?') {
            regex.append(".");
        } else {/*from w  w w .j  a  v  a  2  s  .  co m*/
            regex.append("\\Q").append(tk).append("\\E");
        }
    }
    return Pattern.compile(regex.toString(), ignoreCase ? Pattern.CASE_INSENSITIVE : 0);
}