返回顶部

替换空格

剑指offer

替换空格

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

1 class Solution:
2     # s 源字符串
3     def replaceSpace(self, s):
4         return s.replace(' ', '%20')

 

posted @ 2019-10-10 17:41  Be-myself  阅读(156)  评论(0编辑  收藏  举报
levels of contents 点击查看具体代码内容