Android String Capitalize capitalize(String str)

Here you can find the source of capitalize(String str)

Description

capitalize

Declaration

public static String capitalize(String str) 

Method Source Code

//package com.java2s;

public class Main {
    public static String capitalize(String str) {

        StringBuilder sb = new StringBuilder(str);

        for (int i = 0; i < sb.length(); i++) {
            if (i == 0 || Character.isWhitespace(sb.charAt(i - 1))) {
                sb.replace(i, i + 1, Character.toString(Character
                        .toUpperCase(sb.charAt(i))));
            }/* ww w. j  a v  a2 s.  c o m*/
        }

        return sb.toString();
    }

    public static String replace(String originalString,
            String searchString, String replaceString) {
        StringBuilder sb = new StringBuilder(originalString);
        int index = sb.indexOf(searchString);
        while (index != -1) {
            sb.replace(index, index + searchString.length(), replaceString);
            index += replaceString.length();
            index = sb.indexOf(searchString, index);
        }
        return sb.toString();
    }
}

Related

  1. capitalize(String s)
  2. capitalizeFirstLetter(String src)
  3. capitalize(String s)
  4. capitalize(String str)
  5. capitalizeFirst(String i, Locale l)
  6. capitalize(String s)
  7. capitalize(final String name)
  8. decapitalize(final String name)
  9. capitalize(String string)