String/StringBuffer
1. 将String中的空格替换成 %20
public class ReplaceBlank { public static void main(String[] args) { String str="i am happy"; str=replaceBlank(str); System.out.println(str); } public static String replaceBlank(String str){ if(null==str){ return null; } StringBuffer sb=new StringBuffer(); for(int i=0;i<str.length();i++){ if(str.charAt(i)==' '){ sb.append("%20"); }else{ sb.append(str.charAt(i)); } } return sb.toString(); } }
------------------------- A little Progress a day makes you a big success... ----------------------------