zoukankan      html  css  js  c++  java
  • 将包含_或-的字符串最开始的字母小写,其余的第一个字母大写

    from re import sub
    
    def camel(s):
        print(s)
        # some_database_field_name
        # Some label that needs to be camelized
        # some-javascript-property
        # some-mixed_string with spaces_underscores-and-hyphens
    
        print(sub(r"(_|-)+", " ", s))
        # some database field name
        # Some label that needs to be camelized
        # some javascript property
        # some mixed string with spaces underscores and hyphens
    
        print((sub(r"(_|-)+", " ", s)).title())
        # Some Database Field Name
        # Some Label That Needs To Be Camelized
        # Some Javascript Property
        # Some Mixed String With Spaces Underscores And Hyphens
    
        print((sub(r"(_|-)+", " ", s)).title().replace(" ", ""))
        # SomeDatabaseFieldName
        # SomeLabelThatNeedsToBeCamelized
        # SomeJavascriptProperty
        # SomeMixedStringWithSpacesUnderscoresAndHyphens
    
        s = sub(r"(_|-)+", " ", s).title().replace(" ", "")
        print(s)
        # SomeDatabaseFieldName
        # SomeLabelThatNeedsToBeCamelized
        # SomeJavascriptProperty
        # SomeMixedStringWithSpacesUnderscoresAndHyphens
    
        print(s[0].lower())
        # s
        # s
        # s
        # s
        print(s[0].lower() + s[1:])
        # someDatabaseFieldName
        # someLabelThatNeedsToBeCamelized
        # someJavascriptProperty
        # someMixedStringWithSpacesUnderscoresAndHyphens
    
        # s = sub(r"(_|-)+", " ", s).title().replace(" ", "")
        # print(s[0].lower() + s[1:])
    
    camel('some_database_field_name')
    # someDatabaseFieldName
    camel('Some label that needs to be camelized')
    # someLabelThatNeedsToBeCamelized
    camel('some-javascript-property')
    # someJavascriptProperty
    camel('some-mixed_string with spaces_underscores-and-hyphens')
    # someMixedStringWithSpacesUnderscoresAndHyphens

     

     


    2020-05-03

  • 相关阅读:
    算法:POJ1008 Maya Calendar
    给我的十八岁
    算法:POJ1007 DNA sorting
    算法:POJ1006 三重峰值问题
    【树链剖分】洛谷P3384树剖模板
    【树链剖分】洛谷P3379 树链剖分求LCA
    【Tarjan缩点】PO3352 Road Construction
    【Dijkstra堆优化】洛谷P2243电路维修
    【Tarjan缩点】POJ2186 Popular Cows
    【最短路·差分约束】洛谷P1250
  • 原文地址:https://www.cnblogs.com/hany-postq473111315/p/12821750.html
Copyright © 2011-2022 走看看