注册 登录
编程论坛 JAVA论坛

利用split分割从txt读取到的字符串时,无法去掉每一行开头的空格?

qwer四连 发布于 2017-10-30 21:48, 1985 次点击
数据如下:
xh    sex    poli    chi    math
   92103    2.00    NA    NA    NA
   92239    2.00    40.00    63.00    44.00
   92142    2.00    NaN    70.00    59.00
   92223    1.00    56.00    91.00    65.50
在后几行的开头有空格,我用\\s+,无法去掉,这怎么办
1 回复
#2
calix2017-10-31 13:39
System.out.println(str.trim());
System.out.println(str.replaceFirst("^\\s*", ""));
1