如何用括号内的运算符拆分字符串

时间:2016-06-09 05:54:13

标签: java

我想用','运算符拆分字符串。原始字符串如下所示

input : decode(test,0,nvl(test,0),1)

My expected output:
decode(test
0
nvl(test,0)
1

我尝试了以下程序

String input = "decode(test,0,nvl(test,0),1)";
String[] arr = input.split(",");

帮我解决上述问题

1 个答案:

答案 0 :(得分:3)

试试这个

String arr[ ]= "decode(test,0,nvl(test,0),1)".split ("nvl\\(test,0\\)");

结果

arr[0] == "decode(test,0,"
arr[1] == "nvl(test,0)"
arr[2] == ,1

现在使用arr[0]

分割arr[2]split(",");