Java Bulk replaces a paragraph in a file with a space, wrapping it according to a specified delimiter (SQL example)

Source: Internet
Author: User

My requirement is that there are thousands of similar data in the SQL file, and I want to convert them into formats such as


First step: Replace the character segment, use Word layout to copy the data to Word, replace it with special characters



Click Replace All to replace, for example, when it is a string of long strings


Step two: Write the Java replacement program in code NUM is a split segment, and the 16th character is a newline
public class Demo {public static void main (string[] args) {String s = "' 133 ', ' 153 ', ' 180 ', ' 181 ', ' 189 ', ' 177 ', ' 130 ', ' 131 ', ' 1 32 ', ' 155 ', ' 156 ', ' 145 ', ' 185 ', ' 186 ', ' 176 ', ' 134 ', ' 135 ', ' 136 ', ' 137 ', ' 138 ', ' 139 ', ' 150 ', ' 151 ', ' 152 ', ' 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 is the segmented segment 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));}}
After running as


Step three: Replace the output characters with the SQL characters

such as the following effect




Java Bulk replaces a paragraph in a file with a space, wrapping it according to a specified delimiter (SQL example)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.