public static String capitalizeFirstLetter( String data ) { char firstLetter = Character.toTitleCase( data.substring( 0, 1 ).charAt( 0 ) ); String restLetters = data.substring( 1 ); return firstLetter + restLetters; }
private static String capitalize(String str) { if (str == null || str.length() == 0 || Character.isTitleCase(str.charAt(0))) { return str; } StringBuilder buffer = new StringBuilder(str); buffer.setCharAt(0, Character.toTitleCase(buffer.charAt(0))); return buffer.toString(); }
private static String capitalize(String str) { return String.valueOf(Character.toTitleCase(str.charAt(0))) + str.substring(1); }
private static String capitalize(String str) { return String.valueOf(Character.toTitleCase(str.charAt(0))) + str.substring(1); }
public static String toTitleCase(String input) { StringBuilder titleCase = new StringBuilder(); boolean nextTitleCase = true; for (char c : input.toCharArray()) { if (Character.isSpaceChar(c)) { nextTitleCase = true; } else if (nextTitleCase) { c = Character.toTitleCase(c); nextTitleCase = false; } titleCase.append(c); } return titleCase.toString(); }
final int newCodePoint = Character.toTitleCase(firstCodepoint); if (firstCodepoint == newCodePoint) {
/** * Returns the setter-method for the given field name or null if no setter exists. */ public static Method getSetter(String fieldName, Class<?> clazz, Class<?> fieldType) { String setterName = "set" + Character.toTitleCase(fieldName.charAt(0)) + fieldName.substring(1, fieldName.length()); try { // Using getMethods(), getMethod(...) expects exact parameter type // matching and ignores inheritance-tree. Method[] methods = clazz.getMethods(); for (Method method : methods) { if (method.getName().equals(setterName)) { Class<?>[] paramTypes = method.getParameterTypes(); if (paramTypes != null && paramTypes.length == 1 && paramTypes[0].isAssignableFrom(fieldType)) { return method; } } } return null; } catch (SecurityException e) { throw new ActivitiException("Not allowed to access method " + setterName + " on class " + clazz.getCanonicalName()); } }
/** * <p> * Convert the first letter of target to uppercase (title-case, in fact). * </p> * * @param target the String to be capitalized. If non-String object, toString() * will be called. * @return String the result of capitalizing the target. * @since 1.1.2 */ public static String capitalize(final Object target) { if (target == null) { return null; } final StringBuilder result = new StringBuilder(target.toString()); if (result.length() > 0) { result.setCharAt(0, Character.toTitleCase(result.charAt(0))); } return result.toString(); }
capitalizeNext = true; } else if (capitalizeNext) { buffer[i] = Character.toTitleCase(ch); capitalizeNext = false;
/** * <p> * Capitalise a String. * </p> * <p> * That is, convert the first character into title-case. <code>null</code> is returned as <code>null</code>. * </p> * * @param str the String to capitalise * @return capitalised String */ public static String capitalise( String str ) { if ( str == null ) { return null; } else if ( str.length() == 0 ) { return ""; } else { return new StringBuilder( str.length() ).append( Character.toTitleCase( str.charAt( 0 ) ) ).append( str, 1, str.length() ).toString(); } }
/** * 拼接字符串第二个字符串第一个字母大写 */ public static String concatCapitalize(String concatStr, final String str) { if (isEmpty(concatStr)) { concatStr = EMPTY; } if (str == null || str.length() == 0) { return str; } final char firstChar = str.charAt(0); if (Character.isTitleCase(firstChar)) { // already capitalized return str; } return concatStr + Character.toTitleCase(firstChar) + str.substring(1); }
} else if (Character.isLowerCase(ch)) { if (whitespace) { buffer[i] = Character.toTitleCase(ch); whitespace = false; } else {
private static String capitalizeAndTrim(final String str) { if (str == null || str.length() == 0) { return str; } StringBuilder sb = new StringBuilder(str.length()); boolean capitalizeNext = true; for (char ch : str.toCharArray()) { if (!Character.isLetterOrDigit(ch)) { capitalizeNext = true; continue; } if (capitalizeNext) { if (!Character.isLetter(ch)) { sb.append('_'); } else { ch = Character.toTitleCase(ch); } capitalizeNext = false; } sb.append(ch); } return sb.toString(); }
capitalizeNext = true; } else if (capitalizeNext) { buffer.append(Character.toTitleCase(ch)); capitalizeNext = false; } else {
} else if (Character.isLowerCase(ch)) { if (whitespace) { tmp = Character.toTitleCase(ch); } else { tmp = Character.toUpperCase(ch);
buffer.append( Character.toTitleCase( ch ) ); space = false;
private void setTrueCaseText(CoreLabel l) { String trueCase = l.getString(CoreAnnotations.TrueCaseAnnotation.class); String text = l.word(); String trueCaseText = text; switch (trueCase) { case "UPPER": trueCaseText = text.toUpperCase(); break; case "LOWER": trueCaseText = text.toLowerCase(); break; case "INIT_UPPER": trueCaseText = Character.toTitleCase(text.charAt(0)) + text.substring(1).toLowerCase(); break; case "O": // The model predicted mixed case, so lookup the map: String lower = text.toLowerCase(); if (mixedCaseMap.containsKey(lower)) { trueCaseText = mixedCaseMap.get(lower); } // else leave it as it was? break; } // System.err.println(text + " was classified as " + trueCase + " and so became " + trueCaseText); l.set(CoreAnnotations.TrueCaseTextAnnotation.class, trueCaseText); if (overwriteText) { l.set(CoreAnnotations.TextAnnotation.class, trueCaseText); l.set(CoreAnnotations.ValueAnnotation.class, trueCaseText); } }
buffer[idx] = Character.toTitleCase(buffer[idx]); idx++; idx = findNextWord(buffer, idx, delimiterChars);
/** * <p>Capitalizes a String changing the first letter to title case as * per {@link Character#toTitleCase(char)}. No other letters are changed.</p> * * <p>For a word based algorithm, see {@link WordUtils#capitalize(String)}. * A <code>null</code> input String returns <code>null</code>.</p> * * <pre> * StringUtils.capitalize(null) = null * StringUtils.capitalize("") = "" * StringUtils.capitalize("cat") = "Cat" * StringUtils.capitalize("cAt") = "CAt" * </pre> * * @param str the String to capitalize, may be null * @return the capitalized String, <code>null</code> if null String input * @see WordUtils#capitalize(String) * @see #uncapitalize(String) * @since 2.0 */ public static String capitalize(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return str; } return new StrBuilder(strLen) .append(Character.toTitleCase(str.charAt(0))) .append(str.substring(1)) .toString(); }
@FastMethod @Signature(@Arg("char")) public static Memory title(Environment env, Memory... args) { return StringMemory.valueOf(Character.toTitleCase(chr(args[0]))); }