0
输入:Python 2.7版 - 从字符串中删除特殊字符和驼峰规则它
to-camel-case
to_camel_case
所需的输出:
toCamelCase
我的代码:
def to_camel_case(text):
lst =['_', '-']
if text is None:
return ''
else:
for char in text:
if text in lst:
text = text.replace(char, '').title()
return text
问题: 1)输入可能是一个空字符串 - 上面的代码不会返回'',但无; 2)我不知道title()
方法可以帮助我获得所需的输出(只有' - '之前的每个单词的第一个字母或除第一个之外的'_')。如果可能的话使用正则表达式