Java String trim() 方法
示例
從字串的兩側刪除空格
String myStr = " Hello World! ";
System.out.println(myStr);
System.out.println(myStr.trim());
定義和用法
The trim()
method removes whitespace from both ends of a string.
注意: 此方法不會更改原始字串。
語法
public String trim()
引數
無。
技術詳情
返回 | A String value, which is a copy of the string, without leading and trailing whitespace |
---|
❮ String Methods