字符串空格替换

题目:

  请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。

代码:

1 # -*- coding:utf-8 -*-
2 class Solution:
3     # s 源字符串
4     def replaceSpace(self, s):
5         # write code here
6         return s.replace(' ','%20')

 

posted @ 2017-02-17 16:39  龚小楠  阅读(162)  评论(0编辑  收藏  举报