java字符串去 nbsp_从Java字符串中去除前导和尾随空格

139f5e542e4e545b45ea3183537b0b61.png

慕少森

现在,使用java-11,您可以利用String.stripAPI返回一个值为该字符串的字符串,并删除所有前导和尾随空格。相同的javadoc读取:/** * Returns a string whose value is this string, with all leading * and trailing {@link Character#isWhitespace(int) white space} * removed. *

 * If this {@code String} object represents an empty string, * or if all code points in this string are * {@link Character#isWhitespace(int) white space}, then an empty string * is returned. *

 * Otherwise, returns a substring of this string beginning with the first * code point that is not a {@link Character#isWhitespace(int) white space} * up to and including the last code point that is not a * {@link Character#isWhitespace(int) white space}. *

 * This method may be used to strip * {@link Character#isWhitespace(int) white space} from * the beginning and end of a string. * * @return  a string whose value is this string, with all leading *          and trailing white space removed * * @see Character#isWhitespace(int) * * @since 11 */public String strip()这些示例案例可能是:-System.out.println("  leading".strip()); // prints "leading"System.out.println("trailing  ".strip()); // prints "trailing"System.out.println("  keep this  ".strip()); // prints "keep this"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值