Revision 418368d3-5baa-4697-ad0d-9e408ccbdaf5 - Stack Overflow

Here is the code:

 public class Test {
 	public static void main(String argv[]) {
 		String original="r(1,2,1)=r(1,2,0)+r(1,1,0)r(1,1,0)*r(1,2,0)";
 		StringTest strtest=new StringTest();
 		strtest.setX(original.replace("r(1,2‚0)", "TEST"));
 		System.out.println(original.replace("r(1,2,0)", "TEST"));
 		System.out.println(strtest);
 	}
 }
 
 class StringTest {
 	String x=null;
 
 	public StringTest() {}
 
 	public String toString() {
 		return x;
 	}
 
 	public void setX(String other) {
 		x=other;
 	}
 }

Running this gives output:

 r(1,2,1)=TEST+r(1,1,0)r(1,1,0)*TEST
 r(1,2,1)=r(1,2,0)+r(1,1,0)r(1,1,0)*r(1,2,0)

Why is `x` in `strtest` equal to `original` string and r(1,2,0) is not replaced and how do I fix it?

AltStyle によって変換されたページ (->オリジナル) /