【发布时间】:2015-06-06 22:45:44
【问题描述】:
我尝试阅读有关正则表达式和转义的信息,但没有运气。
我有一个如下所示的字符串:
String s = "4/18/2015|Planned|Linux|Maintenance";
我想用分隔符'|'分割它:
String[] tokens = s.split("|");
我期望的正确结果是
tokens[0] is "4/18/2015",
tokens[1] is "Planned",
tokens[2] is "Linux",
token[3] is "Maintenance",
但它给了我一些像这样的奇怪结果:
tokens[0] is null
tokens[1] is 4
tokens[2] is /
and tokens[3] is 1
我猜这是因为日期中的斜杠“/”就是原因。我尝试搜索许多现有问题并尝试了建议的方法,但无济于事。
【问题讨论】:
-
什么是“奇怪的结果”?
-
Please help me and I will upvote the right answers and accept the best.这很明显,也是意料之中的 :) -
看看这个,ideone.com/qZcIFF
标签: java arrays regex string split