替换空格
来源:互联网 发布:高中数学视频教学软件 编辑:程序博客网 时间:2024/06/06 02:13
请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
//解题思路:遍历字符串找到空格字符串位置,然后用%20替换public class Solution2 { public static String repalceSpace(StringBuffer str){ if (str == null){ return null; } StringBuilder newStr = new StringBuilder(); for (int i=0;i<str.length();i++){ if (str.charAt(i) == ' '){ newStr.append("%20"); } else { newStr.append(str.charAt(i)); // System.out.print(str.charAt(i)); } } return newStr.toString(); } public static void main(String arg[]){ StringBuffer a =new StringBuffer( "We are ready !"); System.out.println("replaceSpace:"+repalceSpace(a)); }}
0 0
- 空格替换
- 替换空格
- 空格替换
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 空格替换
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- python实现网站内部视频批量下载
- initMethod 和 afterPropertiesSet 以及 AwareMethod方法的执行时机
- c#菜鸟学完
- request for member 'getid’ in ‘e1’, which is of non-class type ‘Employee()’
- 近似回文词
- 替换空格
- Android中实现StickyNavLayout自己的小demo
- gcc命令常用选项
- SQL Server数据库锁机制及类型
- C# Json.net Self referencing loop detected for property
- SpringMVC 架构
- 3.2元胞数组
- react native 真机运行问题
- 初识LISP(3)——谓词、字符及数组