转换字符串: “(id,created,employee(id,firstname,employeeType(id),lastname),location)” 到以下输出 ID 创建 雇员 - ID - 名字 - employeeType - ID - 姓 位置
使用正则表达式
是否有任何乐观的解决方案答案 0 :(得分:0)
public static void main(String[] args) {
String a = "(id,created,employee(id,firstname," +
"employeeType(id), lastname),location)";
StringTokenizer tok = new StringTokenizer(a, "(), ");
System.out.println("StringTokenizer example");
while (tok.hasMoreElements()) {
String b = (String)tok.nextElement();
System.out.println(b);
}
System.out.println("Split example");
String[] array = a.split("(),");
for (String ii: array) {
System.out.println(ii);
}
}
}
输出
StringTokenizer example
id
created
employee
id
firstname
employeeType
id
lastname
location
Split example
(id
created
employee(id
firstname
employeeType(id)
lastname)
location)
您可以添加连字符。