作者yuffy0327 (鱼排)
看板java
标题[问题] 字串合并的问题
时间Wed Jan 7 01:43:28 2015
先描述一下状况: 我载入一个txt档案, 内容如下
-----
| test.txt |
|-----|
| IN(ABC) |
| OU(DEF) |
-----
使用 while ((str = reader.readLine()) != null)
将他读取後再使用 String[] as = str.split("[()]");
执行结果: 第一次 as[0] = IN as[1] = ABC
第二次 as[0] = OU as[1] = DEF
问题:我该怎麽做才能得到"ABC, DEF"的字串呢?
不是做System.out.print用途, 是想得到一个String变数里面塞这两个字串
麻烦版上的各位高手帮小弟解答了OTZ
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 118.167.215.110
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/java/M.1420566214.A.3F3.html
1F:推 Killercat: ..er.. StringBuffer如何? 01/07 02:44
2F:→ Killercat: 没有multi thread问题的话 StringBuilder效果一样 01/07 02:44
3F:→ asb0401: 用indexOf取得 ( 跟 ) 的位置 再用subString取下字串? 01/07 08:40
4F:→ fireslayer: 不是把两次的as[1]串起来就好了吗?= = 01/07 11:10
5F:→ PttTime: String as = s.replaceAll(".*\\((.*)\\).*", "$1"); 01/08 22:10
6F:→ PttTime: str 01/08 22:10