Str = "abc|def|ghi^jkl|mno";
String[] Flds = Str.split("[|]");
//Flds[0] = "abc";
//Flds[1] = "def";
//Flds[2] = "ghi^jkl";
//Flds[3] = "mno";


现在,我想知道Flds [2]的子字段,但以下任何一项均无效-

String[] Flds = Str.split("[^]");

String[] Flds = Str.split("[^]]");

String[] Flds = Str.split("^");

最佳答案

您应该分割Flds[2]

String[] subFlds2 = Flds[2].split("\\^");


另外,^regular expressions中的保留字符。您使用[]来转义|,但是,^也表示[]括号内的内容。

关于java - java string.split函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13317313/

10-13 03:06