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

/**
 * This method is used to remove the full domain name from the server broadcast in order to
 * display it properly.//from  w w  w . ja v a 2  s  . c om
 *
 * @param str the string to extract name from
 * @return the name without domain
 */
public static String extractServerName(String str) {
    String returnstring = new String();
    for (int i = 0; i < str.length(); ++i) {
        if (str.charAt(i) == '.') {
            break;
        }
        returnstring += str.charAt(i);
    }
    return returnstring;
}

From source file:Main.java

/**
 * Check to see if a string is a valid Name according to [5] in the
 * XML 1.0 Recommendation.//w w w.j  a  v  a2  s.  c  om
 *
 * @param  name  String to check.
 *
 * @return true if name is a valid Name.
 */
public static boolean isValidName(final String name) {
    if (name == null || name.length() == 0 || !isNameStart(name.charAt(0))) {
        return false;
    }
    for (int i = 1; i < name.length(); ++i) {
        if (!isName(name.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * Writes <CODE>string</CODE> into writer, escaping &, ', ", <, and >
 * with the XML excape strings./*from w  w  w  .j  av a 2s . c o m*/
 */
public static void writeEscapedString(Writer writer, String string) throws IOException {
    for (int i = 0; i < string.length(); i++) {
        char c = string.charAt(i);
        if (c == '<')
            writer.write("&lt;");
        else if (c == '>')
            writer.write("&gt;");
        else if (c == '&')
            writer.write("&amp;");
        else if (c == '\'')
            writer.write("&apos;");
        else if (c == '"')
            writer.write("&quot;");
        else
            writer.write(c);
    }
}

From source file:StringUtil.java

/**
 * Capitalizes the first character of the given string.
 * @param s the String to capitalize// w w  w .ja  va  2 s . c  o m
 * @return the capitalized result
 */
public static String capitalize(String s) {
    if (s.length() == 0)
        return s;
    char c = Character.toUpperCase(s.charAt(0));
    return c + s.substring(1, s.length());
}

From source file:Main.java

/**
 * Capitalizes the 1st character of the given string
 * //  w ww.  ja va2 s  .  c o m
 * @param str the String to capitalize
 * @return the capitalized String
 */
public static String capitalize(String str) {
    if (str == null || str.isEmpty())
        return null;
    return Character.toUpperCase(str.charAt(0)) + str.substring(1);
}

From source file:Main.java

private static String addSpaceIfRequired(String value, int index) {
    if (index == 0)
        return VOID_STRING;
    char precedingChar = value.charAt(index - 1);
    char thisChar = value.charAt(index);
    if (Character.isLowerCase(precedingChar) && Character.isUpperCase(thisChar)
            || Character.isLetter(precedingChar) && Character.isDigit(thisChar)
            || Character.isDigit(precedingChar) && Character.isLetter(thisChar)) {
        return SPACE;
    }//from   w  w w  .  j a va  2s.c om
    if (index + 1 == value.length())
        return VOID_STRING;
    char nextChar = value.charAt(index + 1);
    if (Character.isUpperCase(precedingChar) && Character.isUpperCase(thisChar)
            && Character.isLowerCase(nextChar)) {
        return SPACE;
    }
    return VOID_STRING;
}

From source file:Main.java

private static int countChars(String arg, char c) {
    int count = 0;
    for (int i = 0; i < arg.length(); i++) {
        if (arg.charAt(i) == c)
            count++;/*from w w w.  jav  a 2s.c  o m*/
    }
    return count;
}

From source file:Main.java

public static String capitalize(String line) {
    if (line.isEmpty()) {
        return "";
    }/*from ww w .ja  v  a 2  s .c om*/

    String retString = Character.toUpperCase(line.charAt(0)) + "";

    if (line.length() > 1) {
        retString = retString + line.substring(1);
    }

    return retString;
}

From source file:Main.java

private static int getLastBytes(final String inData) {
    int len = inData.length();
    if (inData.charAt(len - 2) == PAD) {
        return 1;
    } else if (inData.charAt(len - 1) == PAD) {
        return 2;
    } else {// w  w w  .  j a v  a2  s.co  m
        return 3;
    }
}

From source file:com.ggasoftware.jdiuitest.web.selenium.driver.ScreenshotMaker.java

public static String getValidUrl(String logPath) {
    if (logPath == null || logPath.equals(""))
        return "";
    String result = logPath.replace("/", "\\");
    if (result.charAt(1) != ':')
        if (result.substring(0, 3).equals("..\\"))
            result = result.substring(2);
    if (result.charAt(0) != '\\')
        result = "\\" + result;
    return (result.charAt(result.length() - 1) == '\\') ? result : result + "\\";
}