需要建议以更好的方式处理这个问题吗?
我的数据存储为 TAX|CHURCH, Texas, San Antonia, 250.00 | SCHOOL, NEVADA, Park-SCHOOL, 122.1 其中 TAX,CHURCH, SCHOOL 是我不感兴趣但它们的价值的代码。
if (input != null && !"NOTFOUND".equalsIgnoreCase(input)) {
String[] list_str = input.split("\\|");
int list_length = list_str.length;
int i;
for (String asset : list_str) {
System.out.println(" asset : " + asset);
if (asset.contains("TAX")) {
/* get values for "TAX" */
/* replace "TAX" from values */
}
if (asset.contains("CHURCH")) {
input = input.replaceFirst("CHURCH", "");
}
if (asset.contains("SCHOOL")) {
input = input.replaceAll("SCHOOL", "");
}
}
}
System.out.println(" input : " + input); /* final input */
输入条件:
我的输入字符串可能看起来像 =
"TAX|CHURCH, Texas, San Antonia, 250.00 | SCHOOL, NEVADA, Park-SCHOOL, 122.1"
或"CHURCH, Texas, San Antonia, 250.00 | SCHOOL, NEVADA, Park-SCHOOL, 122.1"
或 "TAX|CHURCH, Texas, San Antonia, 250.00"
或 "CHURCH, Texas, San Antonia, 250.00"
我得到的最终输入是“ ,Texas, San Antonia, 250.00 | , NEVADA, Park-, 122.1 ”,但我希望我的最终字符串是
输入=“德克萨斯州,圣安东尼亚,250.00,内华达州,帕克学校,122.1 ”