/** Turn a string into a normalized stock name. * * @param origname any string. * @return the original value if null or empty; otherwise, a string * equal to the original except that spaces are trimmed from beginning * and end, first character is capitalized, and all other characters * are lowercase. */ static String normalizeStockName(String origname) { if (origname == null || origname.length() == 0) { return origname; } StringBuffer seminormal = new StringBuffer( origname.trim().toLowerCase()); for (int ch = 0; ch < seminormal.length() && seminormal.charAt(ch) == ' '; ) { //Note that we did NOT do ch++ seminormal.deleteCharAt(ch); //ch is always 0! } if (seminormal.length() > 0) { //capitalize the 1st character char first = Character.toUpperCase(seminormal.charAt(0)); seminormal.setCharAt(0, first); } return seminormal.toString(); }