替换空格
请实现一个函数,把字符串 s 中的每个空格替换成 "%20"。class Solution {
public:
string replaceSpace(string s) {
string r("");
int i = 0;
for (; i < s.size(); i++)
{
if (s == ' ')
r += "%20";
else
r += s;
}
return r;
}
}; str1 = 'hello , world!'
str1 = '' . join(['%20' if x == ' ' else x for x in str1])
print(str1) {:10_254:} {:10_256:} 杜若左 发表于 2020-3-2 23:49
str1 = 'hello , world!'.replace(" ", "%20")
print(str1)
页:
[1]