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 long[] toLongArray(String[] strings, char c) {
    long[] array = new long[strings.length];

    for (int i = 0; i < strings.length; i++) {
        String string = strings[i].trim();
        if (string.charAt(0) == c && string.charAt(string.length() - 1) == c) {
            string = string.substring(1, string.length() - 1);
        }//w  w w. ja va2  s .  com
        array[i] = Long.parseLong(string);
    }

    return array;
}

From source file:Main.java

/** 
 * According to RFC2812 the channel's name may and must start with one of the
 * following characters.// www  .  j  a  v  a 2s.  com
 * <ul>
 * <li>! == 33 (ASCII)</li>
 * <li># == 35</li>
 * <li>&amp; == 38</li>
 * <li>+ == 43</li>
 * </ul>. 
 * @param str The name to check if it's a channel. 
 * @return <code>true</code> if the argument starts with one of the characters
 *         mentioned above.
 */
public static boolean isChan(String str) {
    int c;
    return (str.length() >= 2) && ((c = str.charAt(0)) == 35 || c == 38 || c == 33 || c == 43);
}

From source file:Main.java

/**
 * @return true if the string is zero-filled ( 0 char filled )
 **//*from w w  w  .j  av a 2  s .c o  m*/
public static boolean isZero(String s) {
    int i = 0, len = s.length();
    while (i < len && (s.charAt(i) == '0')) {
        i++;
    }
    return (i >= len);
}

From source file:Main.java

public static boolean isNumeric(String str) {
    for (int i = 0; i < str.length(); i++) {
        System.out.println(str.charAt(i));
        if (!Character.isDigit(str.charAt(i))) {
            return false;
        }/*  w  w w.  ja v  a  2 s .  c  o m*/
    }
    return true;
}

From source file:Main.java

public static boolean IsYearCorrect(String sRhs) {
    for (int i = 0; i < sRhs.length(); ++i)
        if (!Character.isDigit(sRhs.charAt(i)))
            return false;

    return true;//from   w  ww .j a  v  a  2  s .c  om
}

From source file:Main.java

public static boolean isNumeric(String str) {
    for (int i = str.length(); --i >= 0;) {
        if (!Character.isDigit(str.charAt(i))) {
            return false;
        }/*from ww w.j  a v  a2s .  c  om*/
    }
    return true;
}

From source file:ColorUtils.java

/**
 * Parses a java.awt.Color from an HTML color string in the form '#RRGGBB' where RR, GG, and BB
 * are the red, green, and blue bytes in hexadecimal form
 * //from   ww  w .  j  a  va2 s . c o  m
 * @param htmlColor The HTML color string to parse
 * @return The java.awt.Color represented by the HTML color string
 */
public static Color fromHTML(String htmlColor) {
    int r, g, b;
    if (htmlColor.length() != 7 || htmlColor.charAt(0) != '#')
        throw new IllegalArgumentException(htmlColor + " is not an HTML color string");
    r = Integer.parseInt(htmlColor.substring(1, 3), 16);
    g = Integer.parseInt(htmlColor.substring(3, 5), 16);
    b = Integer.parseInt(htmlColor.substring(5, 7), 16);
    return new Color(r, g, b);
}

From source file:Main.java

private static String getLabelName(String name, char mnemonicKey, boolean addDot) {
    if (name.charAt(0) == mnemonicKey || mnemonicKey == '0') {
        return addDot ? name + "..." : name;
    }/*from   www.  j a v  a 2  s  .co  m*/
    StringBuilder sb = new StringBuilder();
    sb.append(name).append('(').append(mnemonicKey).append(')');
    if (addDot) {
        sb.append("...");
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Decode a string as a glyph position adjustments array, where the string
 * shall adhere to the syntax specified by {@link #encodePositionAdjustments}.
 * @param value the encoded value/*w  w  w  . jav  a 2  s  . c o  m*/
 * @return the position adjustments array
 */
public static int[][] decodePositionAdjustments(String value) {
    int[][] dp = null;
    if (value != null) {
        String[] sa = value.split("\\s");
        if (sa != null) {
            if (sa.length > 0) {
                int na = Integer.parseInt(sa[0]);
                dp = new int[na][4];
                for (int i = 1, n = sa.length, k = 0; i < n; i++) {
                    String s = sa[i];
                    if (s.charAt(0) == 'Z') {
                        int nz = Integer.parseInt(s.substring(1));
                        k += nz;
                    } else {
                        dp[k / 4][k % 4] = Integer.parseInt(s);
                        k += 1;
                    }
                }
            }
        }
    }
    return dp;
}

From source file:Main.java

public static boolean isNumeric(String str) {
    for (int i = 0; i < str.length(); i++) {
        if (!Character.isDigit(str.charAt(i))) {
            return false;
        }//from  w  ww .  ja  va 2  s  .  c om
    }
    return true;
}