The?java string trim() method eliminates leading and trailing spaces. The unicode value of space character is '\u0020'. The?trim() method in?java string?checks this unicode value before and after the?string, if it exists then removes the spaces and returns the omitted?string.
2017-01-09
就是字符串去除字符串最左邊和最右邊的空格
如String i = new String(" ?123 ?123 ?");//字符串最左邊,最右邊以及中間各有2個(gè)空格
System.out.println(i);
System.out.println(i.length());
System.out.println(i.trim());
System.out.println(i.trim().length());
?輸出的結(jié)果為:
? 123 ?132 ?
12
8
123 ?132
因?yàn)閠rim()方法去除了字符串最左邊,最右邊的空格,所以字符串長度少了4,
注:trim()方法無法去除字符串中間的空格
2016-12-25
The?java string trim() method eliminates leading and trailing spaces. The unicode value of space character is '\u0020'. The?trim() method in?java string?checks this unicode value before and after the?string, if it exists then removes the spaces and returns the omitted?string.