Java 代码
class Solution {
public String replaceSpaces(StringBuffer str)
{
while (true)
{
int index = str.indexOf(" ");
if (index == -1)
{
break;
}
else
{
str.replace(index, index+1, "%20");
}
}
return str.toString();
}
}