Java String Camel Case To camelCaseOrSpaceToDashed(String s)

Here you can find the source of camelCaseOrSpaceToDashed(String s)

Description

camel Case Or Space To Dashed

License

Apache License

Declaration

public static String camelCaseOrSpaceToDashed(String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String camelCaseOrSpaceToDashed(String s) {
        //        String dashed = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN,s);
        //        String trimmed = StringUtils.replace(StringUtils.replace(StringUtils.replace(dashed, " -", "-"), "- ", "-"), " ", "-");
        ///*from   ww w . j  a va  2 s . c o m*/
        //        return trimmed.toLowerCase();

        String trimmed = s.replaceAll("[\\s]", "");

        String dashed = trimmed.replaceAll(String.format("%s|%s|%s",
                "(?<=[A-Z])(?=[A-Z][a-z])", "(?<=[^A-Z])(?=[A-Z])",
                "(?<=[A-Za-z])(?=[^A-Za-z])"), "-");

        dashed = dashed.replaceAll("--", "-");

        return dashed.toLowerCase();
    }
}

Related

  1. camel2underline(String s)
  2. camelCase2Delimiter(String name, char delimiter)
  3. camelCaseIt(String mappingName, String separator)
  4. camelCaseMatch(String word, String abbr)
  5. camelCaseNameToConstant(String camelCaseName)
  6. camelCasePrefix(String strPrefix)
  7. camelCaseSpace(final String str)
  8. camelCaseToDash(String input)
  9. camelCaseToDashes(String camelCaseString, int startIndex, String prefix)