split()用|,为什么分割不了,应该怎么办?

qindequan 2010-09-14 09:38:34
public class Test_split {
public static void main(String[] args) {
String tableHead ="stdno|stdtitle_cn|stdtitle_en|stdtitle_ger|issdate|execdate|stdstatus|replaceno|replacedno|adopstdno|adopstdname";
String[] str = tableHead.split("|");
for(int i=0;i<str.length;i++){
System.out.println(i+":"+str[i]);
}
}
}
...全文
421 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ltandfyy 2010-09-14
  • 打赏
  • 举报
回复
public String[] split(String regex)根据给定的正则表达式的匹配来拆分此字符串。
也就是说,参数并不是单纯的用来分割的字符串,要想使用“字符串字面值”都要转义,还有像“.”
xingyanfeng775 2010-09-14
  • 打赏
  • 举报
回复
用\\转义字符
stalendp 2010-09-14
  • 打赏
  • 举报
回复
试试下面的话:
String[] str = tableHead.split("\\|");
zhuzeitou 2010-09-14
  • 打赏
  • 举报
回复
需要转义
用\\|

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧