如何在woaizhonghua字符串中插入一个“,”号 ,使其变成wo,ai,zhong,hua

解决方案 »

  1.   

    没法进行词法分析,如果是汉字“我爱中华”还可以拆分,像“woaizhonghua”不可能吧
      

  2.   


    String temp = "woaizhonghua";
    String temp1=temp.replaceAll("(wo|ai|zhong|hua)", "$1,");
    System.out.println(temp1.substring(0,temp1.length()-1));
      

  3.   

    String temp1=temp.replaceAll("(wo|ai|zhong|hua)","$1,");结果等效于
    String temp2=Pattern.compile("(wo|ai|zhong|hua)").matcher(temp).replaceAll("$1,");