日期:2014-05-18  浏览次数:20654 次

高手进。jsp 的split问题
<% 
String tempstring=" 上 下";  
String[] temp=tempstring.split("\\s+");  
for(int i=0;i <temp.length;i++){  
  String str=temp[i];  
  System.out.println(str);  

%> 

split不能截取字串前面得空格 例如" 上 下"; 截取出来。”上“的前面还是有一个空格
 
  请问高手怎样解决

------解决方案--------------------
System.out.println(str.trim());

------解决方案--------------------
这样改也可以:

String tempstring = " 上 下";
String[] temp = tempstring.trim().split("\\s+");
for (int i = 0; i < temp.length; i++) {
String str = temp[i];
System.out.println(str);
}