Java String Camel to Hyphen camelCaseToHyphens(String s)

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

Description

camel Case To Hyphens

License

Open Source License

Declaration

public static String camelCaseToHyphens(String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String camelCaseToHyphens(String s) {
        String[] pieces = splitCamelCase(s);
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (String piece : pieces) {
            if (first) {
                first = false;/* w  ww.j a  va2s  .c o m*/
            } else {
                sb.append("-");
            }
            sb.append(piece.toUpperCase().toLowerCase());
        }
        return sb.toString();
    }

    public static String[] splitCamelCase(String s) {
        return s.split(String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z])", "(?<=[^A-Z])(?=[A-Z])",
                "(?<=[A-Za-z])(?=[^A-Za-z])"));
    }
}

Related

  1. camelCaseToHyphenated(String s)
  2. camelCaseToHyphenCase(String s)