c# - Adding a newline into a string from text file -


i have text file.

example

i need add newline after every new line text , put every new line surrounded "" or //.

my output should this:

//name disengagement point//
//description automated test case record disengagement point , force-travel characteristic needed point.//
//startrecording forcetravel//
//userinteraction please, start attempting shift gear 1st gear.//
//capture disengagementpoint userinput == 1 pressclutch 1 userinput == 1// //userinteraction please, shift gear neutral.//
//releaseclutch 100 forcetravel == limitreleased//

the method reading text file:

if (!file.exists(measurementpath)) {     string[] readtext = file.readalllines(measurementpath);     foreach (string s in readtext)     {         script = s.replace(" ", " // ");         char[] separator = new char[] { ' ' };         string[] fields = s.split(separator); 

you can use file.readlines, linq + string.format , file.writealllines:

var newlines = file.readlines(measurementpath)     .select(line => string.format("//{0}//", line))     .tolist(); file.writealllines(measurementpath, newlines); 

Comments