题解 | #替换空格#
替换空格
https://www.nowcoder.com/practice/4060ac7e3e404ad1a894ef3e17650423
package main
func ReplaceSpace(s string) string {
tmp := []byte(s)
l := len(tmp)
if l == 0 {
return ""
}
for i := 0; i < l; i++ {
if tmp[i] == byte(' ') {
tmp = append(tmp, 0, 0)
copy(tmp[i+3:], tmp[i+1:l])
tmp[i] = byte('%')
tmp[i+1] = byte('2')
tmp[i+2] = byte('0')
i += 2
l += 2
}
}
return string(tmp)
}

