Skip to content

Commit 4f6583c

Browse files
committed
question string to hump
1 parent 603465e commit 4f6583c

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
这里集中了一些有意思的问题,我用python给出解决方法。
2+
3+
如果看官愿意参与,可以优化或者用其它语言写出解法。
4+
5+
联系方式:qiwsir#gmail.com (# to @)

‎string_to_hump.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#问题
2+
3+
请写一个字符串转成驼峰的方法?
4+
5+
例如:border-bottom-color -> borderBottomColor
6+
7+
#解决
8+
9+
##python解决方法:
10+
#! /usr/bin/env python
11+
#coding:utf-8
12+
13+
def convert(one_string,space_character): #one_string:输入的字符串;space_character:字符串的间隔符,以其做为分隔标志
14+
15+
string_list = str(one_string).split(space_character) #将字符串转化为list
16+
17+
string_hump_list = [word.capitalize() for word in string_list] #str.capitalize():将字符串的首字母转化为大写
18+
19+
hump_string = ''.join(string_hump_list) #将list组合成为字符串,中间无连接符。驼峰样式。
20+
21+
return hump_string
22+
23+
if __name__=='__main__':
24+
print convert("ab-cd-ef","-")
25+
26+
27+
##欢迎补充其它语言的解决方法

‎string_to_hump.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#! /usr/bin/env python
2+
#coding:utf-8
3+
4+
def convert(one_string,space_character): #one_string:输入的字符串;space_character:字符串的间隔符,以其做为分隔标志
5+
6+
string_list = str(one_string).split(space_character) #将字符串转化为list
7+
8+
string_hump_list = [word.capitalize() for word in string_list] #str.capitalize():将字符串的首字母转化为大写
9+
10+
hump_string = ''.join(string_hump_list) #将list组合成为字符串,中间无连接符。驼峰样式。
11+
12+
return hump_string
13+
14+
if __name__=='__main__':
15+
print convert("ab-cd-ef","-")

0 commit comments

Comments
 (0)