标签:字符替换
我的需求是SQL文件中有成千的类似数据,我要将它们进行转换格式,如下图
点击全部替换,替换之后如下图,这时候它是一串很长的字符串
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)); } }
比如下面效果
Java批量将文件中的段落替换成空格,根据指定分隔符换行(SQL示例)
标签:字符替换
原文地址:http://blog.csdn.net/xiaokui_wingfly/article/details/45937941