我希望此函數用字符串數組中的單詞替換'@'和'#'並輸出一個列表。無法取代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" />