C # operation text file appending text at the beginning and end of a row

Source: Internet
Author: User

Cause:

There are seven SQL statements with more than 50 rows. But it cannot be stored in the database as a stored procedure. In this way, sqlstr. append ("and"); must be appended to each row in the background logic written to C.

After:

1. In the console, copy the SQL statement to vs, beautify it, and record each line, that is, ensure that there is no space in the first letter.

2. Copy the beautifying statement to the C: \ test.txt file. Create a newfile.txt file under the same directory to store new files.

3. Write the following to the console:Code:

4. Run the command. You can see that the changed SQL statement is also displayed on the console. Then you can copy newfile.txt.

 
UsingSystem;
 
UsingSystem. Collections. Generic;
 
UsingSystem. LINQ;
 
UsingSystem. text;
UsingSystem. IO;
 
UsingSystem. collections;
 
 
 
NamespaceFileoperation {
 
ClassProgram {
 
Static VoidMain (String[] ARGs ){
 
// Filestream FS = new filestream (@ "C: \ carerror.txt", filemode. Open, fileaccess. readwrite );
 
Streamreader objreader =NewStreamreader (@ "C: \ test.txt", Encoding. Default );
 
Streamwriter Sw =NewStreamwriter (@ "C: \ newfile.txt");
StringSline ="";
 
Arraylist Al =NewArraylist ();
 
While(Sline! =Null){
 
Sline = objreader. Readline ();
 
If(Sline! =Null){
 
Al. Add ("Strsql. append (\""+ Sline +"\");");
 
}
 
}
 
Objreader. Close ();
 
Foreach(StringSInAl ){
Sw. writeline (s );
 
Console. writeline (s );
 
}
 
Sw. Close ();
 
Console. Readline ();
 
}
 
}
 
}

 

Result:

1. The append is successfully completed. Note: In streamreader, please note that if no encoding is added, garbled characters will appear in the output.

2. accumulation.

Related Article

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.