package basic;
public class Replace1 {
/**
*已知字符串 str = "(1=2 or 2=3) and (3=4) and (4=5) to (6=8)"
如何将等号前面的数字分别替换成x,y,z,w
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Replace1.method1();
}
public static void method1(){
String str = "(1=2 or 2=3) and (3=4) and (4=5) to (6=8)";
char a[] = str.toCharArray();
char c[] = new char[] { 'x', 'y', 'z', 'w' ,'p'};
int j = c.length-1;
for (int i = a.length - 1; i >= 0; i--) {
if (a[i] == '=') {
a[i - 1] = c[j];
j--;
}
}
a.toString();
System.out.println(a);
}
}