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 simplifyName(String chordName) {
    String chord = chordName;
    chord = chord.toLowerCase();/*  w  w w  . ja v  a  2 s  . c  o m*/
    // The first letter
    chord = Character.toString(chord.charAt(0)).toUpperCase() + chord.substring(1);
    int theChar = chordName.indexOf("/");
    if (theChar > -1) {
        return chord.substring(0, theChar);
    } else {
        return chord;
    }
}

From source file:Main.java

public static String capitalizeWords(String s) {
    StringBuilder sb = new StringBuilder();
    String[] words = s.split("\\s+");

    for (int i = 0; i < words.length; i++) {
        String word = words[i];
        if (word.length() > 0) {
            sb.append(Character.toUpperCase(word.charAt(0)));
            if (word.length() > 1) {
                sb.append(word.substring(1));
            }//ww w .  j a  v a  2 s.c o  m
        }

        if (i < words.length - 1) {
            sb.append(" ");
        }
    }

    return sb.toString();
}

From source file:Main.java

public static byte hexToByte(String hexString) {
    byte out;/*  w ww  .ja  va  2  s.c  o m*/
    //make a bit representation in an int of the hex value
    int hn = HEX.indexOf(hexString.charAt(0));
    int ln = HEX.indexOf(hexString.charAt(1));
    //now just shift the high order nibble and add them together
    out = (byte) ((hn << 4) | ln);
    return out;
}

From source file:Main.java

public static boolean isPalindrome(String inputString) {
    int len = inputString.length();
    if (len <= 1) {
        return true;
    }//  w ww .ja  v a  2 s .  com
    String newStr = inputString.toUpperCase();
    boolean result = true;
    int counter = len / 2;
    for (int i = 0; i < counter; i++) {
        if (newStr.charAt(i) != newStr.charAt(len - 1 - i)) {
            result = false;
            break;
        }
    }
    return result;
}

From source file:Main.java

public static String nmtokenize(String cs) {
    StringBuilder s = new StringBuilder();
    for (int i = 0; i < cs.length(); i++) {
        char c = cs.charAt(i);
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_')
            s.append(c);/*from   w w  w  .  j a  v  a  2 s. c o  m*/
        else if (c != ' ')
            s.append("." + Integer.toString(c));
    }
    return s.toString();
}

From source file:Main.java

/**
 * Look at the peer ID and just grab as many readable characters to form the version
 * substring as possible./*from   w  ww  .  ja  v  a 2  s . c om*/
 */
public static String extractReadableVersionSubstringFromPeerID(String peer_id) {
    for (int i = 0; i < peer_id.length(); i++) {
        char c = peer_id.charAt(i);

        // This is based on All Peers peer ID at the time of writing, e.g:
        //   AP0.70rc30->>...
        if (Character.isLetter(c))
            continue;
        if (Character.isDigit(c))
            continue;
        if (c == '.')
            continue;
        // Must be delimiter character.
        return peer_id.substring(0, i);
    }
    return peer_id;
}

From source file:Main.java

public static String encodeHtml(String s) {
    StringBuffer out = new StringBuffer();
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c > 127 || c == '"' || c == '<' || c == '>') {
            out.append("&#" + (int) c + ";");
        } else {//w w w  .  ja v a2s.  co  m
            out.append(c);
        }
    }
    return out.toString();
}

From source file:Main.java

/**
 * Checks whether the parameter is a valid compressed IPv6 address
 *
 * @param input//  w w w . ja v a2 s.co  m
 *            the address string to check for validity
 * @return true if the input parameter is a valid compressed IPv6 address
 */
public static boolean isIPv6HexCompressedAddress(final String input) {
    int colonCount = 0;
    for (int i = 0; i < input.length(); i++) {
        if (input.charAt(i) == COLON_CHAR) {
            colonCount++;
        }
    }
    return colonCount <= MAX_COLON_COUNT && IPV6_HEX_COMPRESSED_PATTERN.matcher(input).matches();
}

From source file:Main.java

private static String encodeHTML(String s) {
    StringBuffer out = new StringBuffer();
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c > 127 || c == '"' || c == '<' || c == '>') {
            out.append("&#" + (int) c + ";");
        } else {/*  w  w  w.j  av  a2  s. c  o m*/
            out.append(c);
        }
    }
    return out.toString();
}

From source file:Main.java

private static File createFileOrDir(String path, String fileName, boolean isDir) {
    if (path.charAt(path.length() - 1) != '/') {
        path += '/';
    }/*from  ww  w.  j  a  v a2s .  c  o m*/

    File file = new File(path + fileName);
    if (!isDir) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        file.mkdir();
    }
    return file;
}