gpt4 book ai didi

java - Java中无法分割字符串

转载 作者:行者123 更新时间:2023-12-02 03:30:52 25 4
gpt4 key购买 nike

我有一个字符串“20160630048|上海11选5|2016-06-30 16:47:52|2.000|前三直选/复式”,我想将其拆分为五个字符串:

我的代码:

String splitString = Value; 
String[] arrSplit = splitString.split("|");
String part1 = arrSplit[0];
String part2 = arrSplit[1];
String part3 = arrSplit[2];
String part4 = arrSplit[3];
String part5 = arrSplit[4];

这意味着第一个字符串将包含“|”之前的字符,第二个字符串将包含“|”之后的字符等等。事实上,我得到的值是数字而不是字符串。请指教

结果打印输出:

STRING SPLIT : 2 + 0 + 1 + 6 + 0

最佳答案

您需要转义管道,因为它是正则表达式中使用的特殊字符:|

splitString.split("\\|");
<小时/>

Regex Logical Operators

XY X followed by Y
X|Y Either X or Y
(X) X, as a capturing group

关于java - Java中无法分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38118485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com