이 함수는 '@'및 '#'을 문자열 배열의 단어로 바꾸고 목록을 출력하려고합니다.자바의 특정 문자열 항목을 바꿀 수 없습니다
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);
}
}
}
OUPUT :
<AggregateColumn AggregateFunction="Sum" ID="siteTotalHello" AggregateColumn="Hello" />
<AggregateColumn AggregateFunction="Sum" ID="siteTotalHello" AggregateColumn="Hello" />
<AggregateColumn AggregateFunction="Sum" ID="siteTotalHello" AggregateColumn="Hello" />
나는 첫 번째 반복 후에는 @s 및 #S를 교체했기 때문에 한 번만 작동합니다
<AggregateColumn AggregateFunction="Sum" ID="siteTotalHello" AggregateColumn="Hello" />
<AggregateColumn AggregateFunction="Sum" ID="siteTotalTest" AggregateColumn="Test" />
<AggregateColumn AggregateFunction="Sum" ID="siteTotalTest2" AggregateColumn="Test2" />