擅长:python、mysql、java
<p>我个人更喜欢正则表达式。这是一个为我做的把戏:</p>
<pre><code>import re
def to_camelcase(s):
return re.sub(r'(?!^)_([a-zA-Z])', lambda m: m.group(1).upper(), s)
</code></pre>
<p>使用<code>unutbu</code>的测试:</p>
<pre><code>tests = [('get__this_value', 'get_ThisValue'),
('_get__this_value', '_get_ThisValue'),
('_get__this_value_', '_get_ThisValue_'),
('get_this_value', 'getThisValue'),
('get__this__value', 'get_This_Value')]
for test, expected in tests:
assert to_camelcase(test) == expected
</code></pre>