Java如何从字符串中删除开头和结尾的空格?
package org.nhooo.example.lang;
public class TrimStringExample {
public static void main(String[] args) {
String text = " tattarrattat ";
System.out.println("Original = " + text);
System.out.println("text.length() = " + text.length());
//trim()方法将产生一个新的字符串对象,其前导和
//删除空间时拖尾。
text = text.trim();
System.out.println("Result = " + text);
System.out.println("text.length() = " + text.length());
}
}上面的代码片段的结果:
Original = tattarrattat text.length() = 22 Result = tattarrattat text.length() = 12
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短