题目描述
请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
# -*- 代码-*-
class Solution:
# s 源字符串
def replaceSpace(self, s):
# write code here
return s.replace(' ','%20')
不得不说python太强大了,如果用c写不知道自己要绕多少弯路了
说一下replace方法:返回某字符串的所有匹配项均被替换后得到的字符串
>>>‘This is a test’.replace('is','is not')
'This is not a test'