标签:题目 ++ 字符串 buffer pre public rar int solution
请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
public class Solution {
public String replaceSpace(StringBuffer str) {
String sti = str.toString();
char[] chars = sti.toCharArray();
StringBuffer out = new StringBuffer();
for (int i = 0 ; i < chars.length; i++){
if (chars[i] == ' '){
out.append("%20");
}else {
out.append(chars[i]);
}
}
return out.toString();
}
}
标签:题目 ++ 字符串 buffer pre public rar int solution
原文地址:https://www.cnblogs.com/Tu9oh0st/p/10705207.html