美文网首页
驼峰下划线连字符转换

驼峰下划线连字符转换

作者: 海德堡绝尘 | 来源:发表于2019-12-28 15:34 被阅读0次
import com.google.common.base.CaseFormat;

/**
 * <dependency>
 * <groupId>com.google.guava</groupId>
 * <artifactId>guava</artifactId>
 * <version>23.0</version>
 * </dependency>
 *
 * @Author niewj
 * @Date 2019/12/28 15:05
 * @Version 1.0
 */
public class CamelTest {

    public static void main(String[] args) {
        // test-data ----> testData (小写连字符 --> 小写驼峰)
        System.out.println(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, "test-data"));

        //  test_data----> testData (小写下划线 --> 小写驼峰)
        System.out.println(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "test_data"));

        //  test_data----> TestData  (大写下划线 --> 大写驼峰)
        System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, "test_data"));

        //  testData----> test_data (小写驼峰 --> 小写下划线)
        System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "testData"));

        //  TestData----> test_data (大写驼峰 --> 小写下划线)
        System.out.println(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "TestData"));

        //  testData----> test-data (小写驼峰 --> 小写连字符)
        System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, "testData"));

        // TEST_DATA----> testData (大写下划线 --> 小写驼峰)
        System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "TEST_DATA"));

        // TEST_DATA----> test-data (大写下划线 --> 小写连字符)
        System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, "TEST_DATA"));
    }
}

  • camel=骆驼
  • hyphen=连字符
  • underscore=下划线
  • hyphen和dash区别
    连字符: non-smoker 中是 hyphen
    波折号: 1928-2008 中是 dash

相关文章

网友评论

      本文标题:驼峰下划线连字符转换

      本文链接:https://www.haomeiwen.com/subject/mvysoctx.html