替换空格

使用stringbuffer自带函数解 字符串替换

int index = 0;
while (index < str.length()) {
      index = str.indexOf(" ", index);
      if (index != -1) {
           str.replace(index, ++index, "%20");
      } else {
           break;
      }
}
return str.toString();
posted @ 2019-12-19 13:58  慢慢行  阅读(6)  评论(0编辑  收藏  举报