List of utility methods to do String Underscore
String | underscoreAllWhitespace(String str) Change to underscore all whitespace from the given String: leading, trailing, and inbetween characters. if (str == null || str.length() == 0) { return str; StringBuilder sb = new StringBuilder(str); int index = 0; while (sb.length() > index) { if (Character.isWhitespace(sb.charAt(index))) { sb.replace(index, index + 1, "_"); ... |
String | underscoreAndLowercase(String s) underscore And Lowercase return s.replaceAll(String.format("%s|%s", "(?<=[A-Z])(?=[A-Z][a-z])", "(?<=[^A-Z])(?=[A-Z])"), "_") .toLowerCase(); |
String | underScoreBreakToCaseBreak(final String s) under Score Break To Case Break final StringBuilder sb = new StringBuilder(); final char[] chars = s.toCharArray(); boolean nextShouldBeUpperCase = true; for (final char c : chars) { if (c == '_') { nextShouldBeUpperCase = true; } else if (c == '$' || !Character.isJavaIdentifierPart(c)) { sb.append('_'); ... |
String | underscoreCase(String s) underscore Case if (s.isEmpty()) { return s; StringBuilder sb = new StringBuilder(); char[] chars = s.toCharArray(); sb.append(chars[0]); for (int i = 1; i < chars.length; i++) { char ch = chars[i]; ... |
String | underScoreCase2CamelCase(String str) under Score Case Camel Case if (!str.contains("_")) return str; StringBuilder sb = new StringBuilder(); char[] chars = str.toCharArray(); boolean hitUnderScore = false; sb.append(chars[0]); for (int i = 1; i < chars.length; i++) { char c = chars[i]; ... |
String | underscored(String string) Convert from CamelCase to underscored: MyModel -> my_model. return separated(string, '_'); |
String | underscoredToCamel(String string) underscored To Camel String[] a = string.split("_"); for (int i = 0, n = a.length; i < n; i++) { String s = a[i].trim(); a[i] = capitalize(a[i]); return implode(a, ""); |
String | underscoreName(String camelCaseName) underscore Name StringBuilder result = new StringBuilder(); if (camelCaseName != null && camelCaseName.length() > 0) { result.append(camelCaseName.substring(0, 1).toLowerCase()); for (int i = 1; i < camelCaseName.length(); i++) { char ch = camelCaseName.charAt(i); if (Character.isUpperCase(ch)) { result.append("_"); result.append(Character.toLowerCase(ch)); ... |
String | underscoreName(String name) underscore Name return name.substring(0, 1).toLowerCase() + name.substring(1).replaceAll("([A-Z])", "_$1").toLowerCase(); |
String | underscoreSpaces(String input) underscore Spaces if (input == null) return null; String tmp = input.trim().replaceAll("\\s+", "_"); tmp = tmp.replaceAll("_+", "_"); return tmp; |