1. ()
trim()是去掉首尾空格
ace(" ", ""); 去掉所有空格,包括首尾、中間
String str = " hell o ";
String str2 = aceAll(" ", "");
tln(str2);
3.或者replaceAll(" +",""); 去掉所有空格
= aceAll("s*", "");
可以替換大部分空白字元, 不限於空格
s 可以匹配空格、製表符、換頁符等空白字元的其中任意一個
5.或者下面的程式碼也可以去掉所有空格,包括首尾、中間
public String remove(String resource,char ch) { StringBuffer buffer=new StringBuffer(); int position=0; char currentChar; while(position<th()) { currentChar=At(position++); if(currentChar!=ch) nd(currentChar); } return ring(); }
以上就是本文給大家分享的全部內容了,希望大家能夠喜歡。