我希望此函数用字符串数组中的单词替换'@'和'#'并输出一个列表。无法取代java中的某些字符串项目
import java.util.ArrayList;
import java.util.List;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
String strSpecialties = "hello, test, test2, test3";
strSpecialties.trim();
String []lstSpecialties = strSpecialties.split(",");
String newString = "<AggregateColumn AggregateFunction="+"\"Sum\" " +"ID="+"\"siteTotal#\"" + " AggregateColumn="+"\"@\" />";
for(int i=0; i< lstSpecialties.length; i++){
newString = newString.replace("#", lstSpecialties[i]);
newString = newString.replace("@", lstSpecialties[i]);
System.out.println(newString);
}
}
}
输出继电器:
<AggregateColumn AggregateFunction="Sum" ID="siteTotalHello" AggregateColumn="Hello" />
<AggregateColumn AggregateFunction="Sum" ID="siteTotalHello" AggregateColumn="Hello" />
<AggregateColumn AggregateFunction="Sum" ID="siteTotalHello" AggregateColumn="Hello" />
我想要什么
<AggregateColumn AggregateFunction="Sum" ID="siteTotalHello" AggregateColumn="Hello" />
<AggregateColumn AggregateFunction="Sum" ID="siteTotalTest" AggregateColumn="Test" />
<AggregateColumn AggregateFunction="Sum" ID="siteTotalTest2" AggregateColumn="Test2" />