题目描述

请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
  
class Solution:
    # s 源字符串
    def replaceSpace(self, s):
        # write code here
        #将字符串转换为列表,循环遍历
        temp=list(s)
        n=len(temp)
        s=''
        for i in range(0,n):
            if temp[i]==' ':
                s+='%20'
            else:
                s+=temp[i]
        return s
 

 

 

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄