Here you can find the source of capitalize(String str, char[] wordDelimiters)
Parameter | Description |
---|---|
str | a parameter |
wordDelimiters | a parameter |
public static String capitalize(String str, char[] wordDelimiters)
//package com.java2s; //License from project: Creative Commons License public class Main { /**//from w w w. j ava2 s . c om * Capitalize first letter of each word. * * @param str * @param wordDelimiters * @return */ public static String capitalize(String str, char[] wordDelimiters) { int strLen = str.length(); StringBuffer buffer = new StringBuffer(strLen); boolean capitalizeNext = true; for (int i = 0; i < strLen; i++) { char ch = str.charAt(i); boolean isDelimiter = false; for (int j = 0, isize = wordDelimiters.length; j < isize; j++) { if (ch == wordDelimiters[j]) { isDelimiter = true; } } if (isDelimiter) { buffer.append(ch); capitalizeNext = true; } else if (capitalizeNext) { buffer.append(Character.toTitleCase(ch)); capitalizeNext = false; } else { buffer.append(ch); } } return buffer.toString(); } }