Dear all,
First of all, I am pretty new to C#, but learning quick! :)
At this point I am working on a simple console app.
This app should read through a text file, and when it finds a line that not starts with a certain code (6 options, like ":20:" or ":86:"), it should go one (or more) line back and appends the line without the code to the line with the code.
Example:
input:
:86:1234567890
ABCD
EFGH
output:
:86:1234567890ABCDEFGH
Can someone point me in the correct direction, or maybe post some code?
Thanks in advance!!
Loading
SteefPosted Apr 17, 2008, 4:43 AM
AlanPosted Apr 17, 2008, 4:30 AM
Try this (requires .NET 2.0 or later):
using System;
using System.IO;
using System.Collections.Generic;
class Program output = new List();
{
static void Main()
{
string[] input = File.ReadAllLines("steef.txt");
List
string temp = "";
foreach (string line in input)
{
if (line.StartsWith(":20:") || line.StartsWith(":86:"))
{
if (temp != "") output.Add(temp);
temp = line;
}
else if (line != "")
{
temp += line;
}
}
output.Add(temp);
// check it worked
foreach(string line in output)
{
Console.WriteLine(line);
}
Console.ReadKey();
}
}