我的需求是SQL文件中有成千的类似数据,我要将它们进行转换格式,如下图
第一步:将字符段楼替换,使用word排版
把数据拷贝到word中,使用特殊字符替换
点击全部替换,替换之后如下图,这时候它是一串很长的字符串
第二步:编写Java替换程序
在代码中num是分割段,到第16个字符时候换行
public class Demo { public static void main(String[] args) { String s = "'133','153','180','181','189','177','130','131','132','155','156','145','185','186','176','134','135','136','137','138','139','150','151','152','158','159','182','183','184','157','187','188','147','178','170'"; String str[] = s.split(","); StringBuilder sb = new StringBuilder(); StringBuilder rs = new StringBuilder(); int num = 15; // 15是分割段 int yu = str.length % num; int a = 0; for (int i = 0; i < str.length; i++) { a++; sb.append(str[i] + ","); if (a == num) { a = 0; rs.append(sb + "\n"); sb = new StringBuilder(); } } sb = new StringBuilder(); for (int i = yu; i > 0; i--) { sb.append(str[str.length - i] + ","); } rs.append(sb); System.out.println(rs.substring(0, rs.length() - 1)); System.out.println("\n" + str.length + " : " + (rs.toString().split(",").length)); } }
运行之后如下图
第三步:将输出的字符替换SQL字符即可
比如下面效果