String Inf = "商品号:[1234567890]金额:[3333.00]联单号:[87373737]"有办法实现在商品号、金额、联单号前空两个格或者另排一行         商品号:[1234567890]  金额:[3333.00]  联单号:[87373737]"
或者
商品号:[1234567890]
金额:[3333.00]
联单号:[87373737]"

解决方案 »

  1.   

    Inf.replaceAll("]", "]  ")
      

  2.   

    如果他们的没用的话、你用我这种最原始的方法:
    String Inf = "商品号:[1234567890]"+" "+"金额:[3333.00]"+" "+" 联单号:[87373737]";
    String Inf2 = "商品号:[1234567890]"+"\n"+"金额:[3333.00]"+"\n"+"联单号:[87373737]";
      

  3.   

    楼上已经给思路了,用正则来实现就行了:package CSDN;public class StrRegExp {
    public static void main(String[] args) {
    String Inf = "商品号:[1234567890]金额:[3333.00]联单号:[87373737]".replace("]", "]\t");
    System.out.print(Inf);
    System.out.println();
    String inf = "商品号:[1234567890]金额:[3333.00]联单号:[87373737]".replace("]", "]\n");
    System.out.print(inf);
    }
    }
      

  4.   

    Java中有时候会出现消除默认空格的问题,所以建议使用1楼的做法!
      

  5.   


    String sss = "商品号:[1234567890]金额:[3333.00]联单号:[87373737]";
    Pattern p = Pattern.compile(".+?(?>\\])");
    Matcher m = p.matcher(sss);
    while(m.find()) {
    System.out.println(m.group());
    }