给定一个string iniString 及其长度 int len, 已知该字符串中有空格,现要求编写程序将字符串中空格替换为“%20”。返回更改后的string。假设该字符串有足够的空间存放新增的字符,并且知道原字符的长度(小于等于1000),同时保证字符串由大小写的英文字母组成。
示例1
输入
"Mr John Smith",13
输出
"Mr%20John%20Smith"
示例2
输入
"Hello World",12
输出
"Hello%20%20World"
加载中...
import java.util.*; public class Replacement { public String replaceSpace(String iniString, int length) { // write code here } }
class Replacement { public: string replaceSpace(string iniString, int length) { // write code here } };
# -*- coding:utf-8 -*- class Replacement: def replaceSpace(self, iniString, length): # write code here
class Replacement { public string replaceSpace(string iniString, int length) { // write code here } }
"Mr John Smith",13
"Mr%20John%20Smith"
"Hello World",12
"Hello%20%20World"