注明:我们公司的数据库不支持split函数(如果支持这个函数就好办拉)

解决方案 »

  1.   

    String test="'DG,HK,GZ'";
    String result = test.replaceAll(",","','");
    System.out.println(result);行吗?
      

  2.   

    楼上的,这样可是可以,问题就是我的test这个变量的内容是不确定的呀,如果是
    test="SZ"那怎么控制呢?
    又如果test="sz,GF,UK,VF,BJ"那又怎么处理呢?不过都谢谢你
      

  3.   

    Java中有Split函数用StringTokenizer也可以
      

  4.   


    class Cls{
     public static void main(String[] args){
         String test="DG,HK,GZ";
         String result = test.replaceAll( "([a-zA-Z]{2})(,?)", "'" + "$1" + "'$2" );
         System.out.println(result);
         test = "SZ,GF,UK,VF,BJ";
         result = test.replaceAll( "([a-zA-Z]{2})(,?)", "'" + "$1" + "'$2" );
         System.out.println(result);
         test = "SJ";
         result = test.replaceAll( "([a-zA-Z]{2})(,?)", "'" + "$1" + "'$2" );
         System.out.println(result);
      }
    }