如何对字符串首部和尾部的空格进行过滤

来源:互联网 发布:淘宝汽车凹陷修复工具 编辑:程序博客网 时间:2024/05/01 01:20

if (jsonObj.has("DtlContentTruncate")) {
     historical.setContent(jsonObj.getString("DtlContentTruncate").trim());
    }

 

其中的.trim()的作用就是过滤掉字符串首尾的空格;

 

String.Trim()方法会去除字符串两端,不仅仅是空格字符,它总共能去除25种字符:
('/t', '/n', '/v', '/f', '/r', ' ', '/x0085', '/x00a0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '?', '/u2028', '/u2029', ' ', '?')