Java String Upper Case toUpperCaseAscii(String s)

Here you can find the source of toUpperCaseAscii(String s)

Description

Returns a string with all ASCII lower-case letters converted to upper-case.

License

Creative Commons License

Parameter

Parameter Description
s a string.

Declaration


public static String toUpperCaseAscii(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w  ww. j a v a 2 s.c  o m*/
     * Returns a string with all ASCII lower-case letters
     * converted to upper-case.
     * 
     * @param s a string.
     */

    public static String toUpperCaseAscii(String s) {
        if (s == null)
            return null;
        int len = s.length();
        char c = 0;
        boolean hasLowerCase = false;
        for (int i = 0; i < len; i++) {
            c = s.charAt(i);
            if (c >= 'a' && c <= 'z') {
                hasLowerCase = true;
                break;
            }
        }
        if (!hasLowerCase)
            return s;
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < len; i++) {
            c = s.charAt(i);
            if (c >= 'a' && c <= 'z') {
                builder.append((char) (c - 0x20));
            } else {
                builder.append(c);
            }
        }
        return builder.toString();
    }
}

Related

  1. toUpperCase(String[] list)
  2. toUpperCase(String[] source)
  3. toUpperCase(StringBuffer buf)
  4. toUppercaseAndUnderscore(String string)
  5. toUpperCaseArray(String[] source, String[] target)
  6. toUpperCaseAt(String oldString, int index)
  7. toUpperCaseAtFirstChar(String string)
  8. toUpperCaseFirst(String str)
  9. toUpperCaseFirst(String str)