This is what happens. I have a huge text file, which should be 1 line per record. The problem is that sometimes a line breaks into a new line.
I am editing this whole file and wherever the file starts ("\" A), I need to add the current line to the previous line (replacing \ n with ""). All I came up with is adding a line to a new line. Any help is available ...
THE CODE:
public void step1a() { string begins = ("\"A"); string betaFilePath = @"C:\ext.txt"; string[] lines = File.ReadAllLines(betaFilePath); foreach (string line in lines) { if (line.StartsWith(begins)) { File.AppendAllText(@"C:\xt2.txt",line); File.AppendAllText(@"C:\xt2.txt", "\n"); } else { string line2 = line.Replace(Environment.NewLine, " "); File.AppendAllText(@"C:\xt2.txt",line2); } } }
Example: Orig:
"\" "Hero | apple | orange" for the pleasure of this | "\" "Hero | apple | mango | lots of fun always
"No \" A "Her | apple | fruit | no
pain is the way "\" A "Hero | love | stackoverflowpeople | more fun
RESULT OF:
"\" "Hero | apple | orange" for the pleasure of this | "\" "Hero | apple | mango | lots of fun always
"\" "Her | apple | fruit | no pain - the way |" \ "A" Hero | love | stackoverflowpeople | More fun
My problem is not finding if (line.StartsWith (starts)) its else statement, it adds line2 to a new line
user222427
source share