SH1265, SH5951, SH6766, SH7235, SH1265, SH5951, SH6766, SH7235 变成 'SH1265', 'SH5951', 'SH6766', 'SH7235', 'SH1265', 'SH5951', 'SH6766', 'SH7235' 

解决方案 »

  1.   


    public static void main(String[] args) {
      String str = "SH1265, SH5951, SH6766, SH7235, SH1265, SH5951, SH6766, SH7235";
          String[] strNum = str.split(",");
          for(String m : strNum){
           System.out.print("'"+m+"'");
          }   
    }
    }
      

  2.   


    class Test1 {
        public static void main(String[] args){
    String[] strs = {"SH1265", "SH5951", "SH6766", "SH7235", "SH1265", "SH5951", "SH6766", "SH7235 "};
    for(String str : strs){
    System.out.println(str);
    str ='\''+str + '\'';
    System.out.println(str);
    }
        }
    }是这样吗?
      

  3.   

    替换SH + 4个数字的:
    s.replaceAll("(SH[0-9]{4})", "'$1'")
    替换字母 + 数字的:
    s.replaceAll("([a-zA-Z]+[0-9]+)", "'$1'")
      

  4.   

    public static void main(String[] args) {
    String src = "SH1265, SH5951, SH6766, SH7235, SH1265, SH5951, SH6766, SH7235";
    src = "'" + src.replaceAll("\\s*,\\s*", "','") + "'";
    System.out.println(src);
    }