Java String Underscore underscoreName(String camelCaseName)

Here you can find the source of underscoreName(String camelCaseName)

Description

underscore Name

License

Open Source License

Declaration

public static String underscoreName(String camelCaseName) 

Method Source Code

//package com.java2s;
/*//from ww w.ja va  2 s. com
 * Project: admin-parent
 * 
 * File Created at 2014-04-03
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */

public class Main {

    public static String underscoreName(String camelCaseName) {
        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));
                } else {
                    result.append(ch);
                }
            }
        }
        return result.toString();
    }
}

Related

  1. underScoreBreakToCaseBreak (final String s)
  2. underscoreCase(String s)
  3. underScoreCase2CamelCase(String str)
  4. underscored(String string)
  5. underscoredToCamel(String string)
  6. underscoreName(String name)
  7. underscoreSpaces(String input)
  8. underscoreSpaces(String str)