Java String Underscore toUnderscore(String v)

Here you can find the source of toUnderscore(String v)

Description

userName -> user_name Password -> _password

License

Apache License

Parameter

Parameter Description
v a parameter

Declaration

public static String toUnderscore(String v) 

Method Source Code

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

public class Main {
    /**/* w w  w  .  j  a va2  s  .co  m*/
     * userName -> user_name
     * Password -> _password
     * @param v
     * @return
     */
    public static String toUnderscore(String v) {
        StringBuilder sb = new StringBuilder();
        char[] chars = v.toCharArray();
        // 65-90 A-Z
        // 97-112 a-z
        for (char ch : chars) {
            if (ch >= 65 && ch <= 90) {
                sb.append("_");
            }
            sb.append(Character.toLowerCase(ch));
        }
        return sb.toString();
    }
}

Related

  1. toUnderscore(final String input, final boolean plural)
  2. toUnderscore(String s)
  3. toUnderscore(String text)
  4. toUnderscoreCase(final String s)
  5. toUnderscoreCase(String name)
  6. toUnderScoreCase(String s)
  7. toUnderScoreCase(String s)