【发布时间】:2022-01-22 09:41:04
【问题描述】:
我想拆分由“|”分隔的字符串。但要忽略具有“|”的字符串值。 查找以下示例:
String s = "Shashank|Sam|Location|20246|India|City in India|USA Country|Location|India Specific 2021|25236|A";
我想将Location|India Specific 2021 视为一个值。
预期输出:
Shashank
Sam
Location
20246
India
City in India
USA Country
Location|India Specific 2021
25236
A
每当我在字符串中找到Location|India 时,我都想忽略其中的|。
我尝试过使用
(?<!Location|India)\|
但是输出是
Shashank
Sam
Location|20246
India
City in India
USA Country
Location|India Specific 2021
25236
A
谢谢
【问题讨论】:
-
但在这种情况下,如果我只有 Location 作为值,它会考虑这一点。像 Shashank|Sam|位置|25643|位置|印度。在这个我也会得到 Location|25643
-
为什么在
Location和其他文本之间构建管道?将状态分配为非分隔符是一个概念错误。来源应该是"Shashank|Sam|Location 20246|India|City in India|USA Country|Location India Specific 2021|25236|A"