使用java拆分字符串并获取每个值

使用java拆分字符串并获取每个值,java,string,Java,String,我有一个以下格式的字符串 Duplicate application\Your request has been rejected by the Credit Bureau server.\Entered value is lower than the minimum requirement to apply with this Income proof document. Please try using any other Income Support Document.\Validatio

我有一个以下格式的字符串

Duplicate application\Your request has been rejected by the Credit Bureau server.\Entered value is lower than the minimum requirement to apply with this Income proof document. Please try using any other Income Support Document.\Validation error. Policy criteria not met.\Decisioning System unavailable at the moment\Decision Center error:\We regret not being able to take your application forward at this point. Thank you for applying.
现在,我尝试使用分隔符“\”拆分字符串。我试图获取所有字符串,并将从响应中收到的字符串与每个值的拆分结果进行比较。我没弄清楚确切的情况。。这是我的密码

//Note SCBCC_NEW is the string which I will have..

String[] scbCCNewArray = SCBCC_NEW.split("/");
    for(String results : scbCCNewArray) {
        LOG.info("Value :"+results)
    }

这条路对吗

您需要将反斜杠转义为java中的一个特殊字符

String str = "Duplicate application\\Your request has been rejected by the Credit Bureau server.\\Entere";
String[] scbCCNewArray = str.split("\\\\");
for (String results : scbCCNewArray) {
     System.out.println("Value :" + results);
}
Output:
Value :Duplicate application
Value :Your request has been rejected by the Credit Bureau server.
Value :Entere

您需要将反斜杠转义为java中的一个特殊字符

String str = "Duplicate application\\Your request has been rejected by the Credit Bureau server.\\Entere";
String[] scbCCNewArray = str.split("\\\\");
for (String results : scbCCNewArray) {
     System.out.println("Value :" + results);
}
Output:
Value :Duplicate application
Value :Your request has been rejected by the Credit Bureau server.
Value :Entere
如果您想知道为什么需要四个
\
,请添加:

\
是正则表达式中的一个特殊字符,用于转义其他特殊字符。因此,我们需要使用
\\
在正则表达式级别转义转义字符,以便正则表达式将其视为普通字符

然后是java,其中
\
。因此,我们必须为正则表达式级别上已有的每个反斜杠添加一个转义反斜杠。这将是所需反斜杠的总数。

如果您想知道为什么需要四个反斜杠,请添加一个:

\
是正则表达式中的一个特殊字符,用于转义其他特殊字符。因此,我们需要使用
\\
在正则表达式级别转义转义字符,以便正则表达式将其视为普通字符


然后是java,其中
\
。因此,我们必须为正则表达式级别上已有的每个反斜杠添加一个转义反斜杠。这将是所需反斜杠的总数。

是的,这是正确的方法。打字错误更正:
.split(“\”)
这是反斜杠。是的,这是正确的方式。打字错误更正:
.split(“\”)
这是反斜杠。谢谢Sergey。你的另一个解决方案是什么?@Nizam我脑子里没有任何解决方案能打败弦。split()谢谢Sergey。你的替代解决方案是什么?@Nizam我脑子里没有比String.split()更好的解决方案