请问在java中如何实现这样的字符串替换: 
   已知字符串 str = "(1=2 or 2=3) and (3=4) and (4=5)" 
    如何将等号前面的数字分别替换成x,y,z,w

解决方案 »

  1.   

    str = str.repalceAll("1=",'x=');
    str = str.repalceAll("2=",'y=');
    str = str.repalceAll("3=",'z=');
    str = str.repalceAll("4=",'w=');
      

  2.   

    str = str.repalceAll("1=","x="); 
    str = str.repalceAll("2=","y="); 
    str = str.repalceAll("3=","z="); 
    str = str.repalceAll("4=","w=");
      

  3.   

    揭贴率:10.53%Do you mean this:str = "(1=2 or 2=3) and (3=4) and (4=5)";String output = str.replaceAll("1", "x").replaceAll("2", "y").replaceAll("3", "z").replaceAll("4", "w");System.out.print(output); 
      

  4.   

    str = str.repalceAll("1=",'x='); 
    str = str.repalceAll("2=",'y='); 
    str = str.repalceAll("3=",'z='); 
    str = str.repalceAll("4=",'w=');
      

  5.   

    其实LZ的意思是: String str = "(1=2 or 2=3) and (3=4) and (4=5)";
    str = str.replaceAll("1", "x");
    str = str.replaceAll("2", "y");
    str = str.replaceAll("3", "z");
    str = str.replaceAll("4", "w");
    str = str.replaceAll("5", "v");
    System.out.println(str);