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 isWhitespace(String s) {
    boolean ok = true;
    for (int i = 0; i < s.length(); i++)
        ok = ok && Character.isWhitespace(s.charAt(i));
    return ok;/*  w  w w  .j a v a2s.co  m*/

}

From source file:Main.java

public static boolean isValidSaveName(String fileName) {

    int len = fileName.length();
    for (int i = 0; i < len; i++) {
        char c = fileName.charAt(i);

        if (c == '\\' || c == ':' || c == '/' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>'
                || c == '|' || c == '\t' || c == '\n') {
            return false;
        }//from  w  w w .jav a2s  .  c  o  m
    }
    return true;
}

From source file:Main.java

static private String capitalize(String s) {
    if (s == null || s.length() == 0) {
        return "";
    }//ww  w  .j a  v a2 s .  c o m
    char first = s.charAt(0);
    if (Character.isUpperCase(first)) {
        return s;
    } else {
        return Character.toUpperCase(first) + s.substring(1);
    }
}

From source file:Main.java

public static String capitalize(String str) {
    return (str == null || str.length() == 0) ? "" : Character.toUpperCase(str.charAt(0)) + str.substring(1);
}

From source file:Main.java

public static String getCheckNum(String ggaString) {
    if (!ggaString.contains("$") || !ggaString.contains("*"))
        return null;
    String test = ggaString.substring(ggaString.indexOf("$") + 1, ggaString.indexOf("*"));
    char result = test.charAt(0);
    for (int i = 1; i < test.length(); i++)
        result ^= test.charAt(i);//from w ww  .  j  a  va2  s . c  om
    String bufferString = Integer.toHexString(result);
    if (bufferString.length() == 1)
        bufferString = "0".concat(bufferString);
    return bufferString;
}

From source file:Main.java

public static String makeCheckDegit(String s) {
    int odd = 0, even = 0;
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        int a = Integer.parseInt("" + c);
        if (i % 2 == 0) {
            odd += a;// w ww .j  av a  2  s.c om
        } else {
            even += a;
        }
    }
    int degit = 10 - ((even * 3 + odd) % 10);
    if (degit < 0 || degit >= 10) {
        degit = 0;
    }
    return String.valueOf(degit);
}

From source file:Main.java

/**
 * Determine if a String contains any XML special characters, return true
 * if it does.  If this function returns true, the string will need to be
 * encoded either using the stringEncodeXML function above or using a
 * CDATA section.  Note that MSXML has a nasty bug whereby whitespace
 * characters outside of a CDATA section are lost when parsing.  To
 * avoid hitting this bug, this method treats many whitespace characters
 * as "special".//from  w ww  .ja v  a  2  s .c om
 * @param input the String to scan for XML special characters.
 * @return true if the String contains any such characters.
 */
public static boolean stringHasXMLSpecials(String input) {
    for (int i = 0; i < input.length(); i++) {
        char c = input.charAt(i);
        switch (c) {
        case '<':
        case '>':
        case '"':
        case '\'':
        case '&':
        case '\t':
        case '\n':
        case '\r':
            return true;
        }
    }
    return false;
}

From source file:Main.java

private static byte bits2byteReverse(String bString) {
    byte result = 0;
    for (int i = 0, j = 0; i < 8; i++, j++) {
        result += (Byte.parseByte(bString.charAt(i) + "") * Math.pow(2, j));
    }/*from w  w  w  .j a va2  s  .c om*/
    return result;
}

From source file:Main.java

private static String removeUnecessaryIndent(String docs) {
    int count = 0;
    String[] lines = docs.split("\n");
    if (lines == null || lines.length == 0)
        return docs;
    String tmp = lines[0];
    if (tmp != null && tmp.length() > 0) {
        while (tmp.charAt(0) == ' ') {
            count++;/*  ww  w . j  a v a  2s .  c om*/
            if (tmp.length() == 1)
                break;
            tmp = tmp.substring(1);
        }
    }
    StringBuffer modified = new StringBuffer();
    for (int i = 0; i < lines.length; i++) {
        String line = lines[i];
        if (line.length() > count) {
            if (line.substring(0, count).trim().length() == 0) {
                line = line.substring(count);
            }
        }
        modified.append(line);
        modified.append("\n");
    }
    modified.deleteCharAt(modified.length() - 1); // remove last newline
    return modified.toString();
}

From source file:Main.java

/**
 * Ensures that the given pathname does not end with the path separator character
 * of this operating system./*from   w  w  w  .j  a v a  2  s.  c o  m*/
 * 
 * @param pathName
 * @return
 */
public final static String ensureEndsNotWithPathSeparatorChar(String pathName) {
    if (pathName.length() == 0)
        return pathName;
    else if (pathName.charAt(pathName.length() - 1) != File.pathSeparatorChar)
        return pathName;
    else
        return pathName.substring(0, pathName.length() - 1);
}