java 字符串 解析

[复制链接]
查看11 | 回复5 | 2010-7-26 14:38:55 | 显示全部楼层 |阅读模式
cmis1
8.31.14410
collecting
我要把这个字符串 解析成数组
cmis1
8.31.14410
collecting
不要中间的空格怎么搞
s[0]=cmis1
s[1]=8.31.14410
s[2]=collecting

回复

使用道具 举报

千问 | 2010-7-26 14:38:55 | 显示全部楼层
不能简单用split(" "),要考虑多个空格的。String str = "cmis1
8.31.14410
collecting";String[] array = str.split("\\s+");for (int i = 0; i < array.length; i++) { System.out.println(array);}
回复

使用道具 举报

千问 | 2010-7-26 14:38:55 | 显示全部楼层
public class A {public static void main(String[] args) { String a="cmis1
8.31.14410
collecting"; StringTokenizer str=new StringTokenizer(a); String []
回复

使用道具 举报

千问 | 2010-7-26 14:38:55 | 显示全部楼层
哥写错了,没咋注意多个空格,以为只是楼主随便分割的,呵呵,3楼正解
回复

使用道具 举报

千问 | 2010-7-26 14:38:55 | 显示全部楼层
String str = cmis1 8.31.14410 collecting;String[] result = str.split(" ");
回复

使用道具 举报

千问 | 2010-7-26 14:38:55 | 显示全部楼层
string.replaceAll("\\s+"," "); 先用这个变成只间隔一个空格,然后再使用split 方法就行了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行