我想写一个简短的程序来代替字符串的计数。所以我想以 0 insted of 1 开始字符串。而且因为它是一个长字符串,我不想自己更改它。所以字符串(在这个例子中)是:字符串 LINE:
- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore
- magna aliquyam erat,sed diam voluptua。
- 在 vero eos et accusam et justo duo dolores et ea rebum。Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum
- dolor 坐在一起。Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore
- magna aliquyam erat,sed diam voluptua。在 vero eos et accusam et justo duo dolores et ea rebum。Stet clita kasd gubergren,
- no sea takimata sanctus est Lorem ipsum dolor sit amet。
我希望字符串从 0 开始计数。然后继续 1.2.3....(0,1,2,3,4...)
public static void main(String[] args) {
for (int counter = 1; counter <= 300; counter++) {
int NormCounter =1;
int ReplaceCounter = 0;
String NormCounterS = (new Integer(NormCounter)).toString() + ".";
String ReplaceCounterS = (new Integer(ReplaceCounter)).toString() + ".";
Line = Line.replace(NormCounterS , ReplaceCounterS);
++ReplaceCounter;
++NormCounter;
}
System.out.println(Line);
}
它只是改变了第一个“1”。进入“0。”......所以它的0,2,3,4......但我希望计数去0,1,2,3,4