File tree 2 files changed +20
-9
lines changed
2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 7
7
#解决
8
8
9
9
##python解决方法:
10
- #! /usr/bin/env python
11
- #coding: utf-8
12
-
13
10
def convert(one_string,space_character): #one_string:输入的字符串;space_character:字符串的间隔符,以其做为分隔标志
14
-
11
+
15
12
string_list = str(one_string).split(space_character) #将字符串转化为list
13
+ first = string_list[0].lower()
14
+ others = string_list[1:]
15
+
16
+ others_capital = [word.capitalize() for word in others] #str.capitalize():将字符串的首字母转化为大写
16
17
17
- string_hump_list = [word.capitalize() for word in string_list] #str.capitalize():将字符串的首字母转化为大写
18
+ others_capital[0:0] = [first]
18
19
19
- hump_string = ''.join(string_hump_list ) #将list组合成为字符串,中间无连接符。驼峰样式 。
20
+ hump_string = ''.join(others_capital ) #将list组合成为字符串,中间无连接符。
20
21
21
22
return hump_string
22
23
23
24
if __name__=='__main__':
25
+ print "the string is:ab-cd-ef"
26
+ print "convert to hump:"
24
27
print convert("ab-cd-ef","-")
25
-
28
+
26
29
27
30
##欢迎补充其它语言的解决方法
31
+
32
+ #联系我:老齐 qiwsir#gmail.com (# to @)
Original file line number Diff line number Diff line change 4
4
def convert (one_string ,space_character ): #one_string:输入的字符串;space_character:字符串的间隔符,以其做为分隔标志
5
5
6
6
string_list = str (one_string ).split (space_character ) #将字符串转化为list
7
+ first = string_list [0 ].lower ()
8
+ others = string_list [1 :]
7
9
8
- string_hump_list = [word .capitalize () for word in string_list ] #str.capitalize():将字符串的首字母转化为大写
10
+ others_capital = [word .capitalize () for word in others ] #str.capitalize():将字符串的首字母转化为大写
9
11
10
- hump_string = '' .join (string_hump_list ) #将list组合成为字符串,中间无连接符。驼峰样式。
12
+ others_capital [0 :0 ] = [first ]
13
+
14
+ hump_string = '' .join (others_capital ) #将list组合成为字符串,中间无连接符。
11
15
12
16
return hump_string
13
17
14
18
if __name__ == '__main__' :
19
+ print "the string is:ab-cd-ef"
20
+ print "convert to hump:"
15
21
print convert ("ab-cd-ef" ,"-" )
You can’t perform that action at this time.
0 commit comments