what i'm trying to do here is to delete the longest line from a txt file. Code does it's job, but i also need it to delete multiple "longest lines" and blank lines as well. Any ideas on how to do it?
Code is in C#
namespace _5_2
{
//------------------------------------------------------------
class Program
{
const string CFd = "..\\..\\U1.txt";
const string CFr = "..\\..\\Results.txt";
static void Main(string[] args)
{
int nr;
Read(CFd, out nr);
Print(CFd, CFr, nr);
Console.WriteLine("Longest line nr. {0, 4:d}", nr + 1);
Console.WriteLine("Program done");
}
//------------------------------------------------------------
/** Finds number of the longest line.
@param fv - text file name
@param nr - number of the longest line */
//------------------------------------------------------------
static void Read(string fv, out int nr)
{
string[] lines = File.ReadAllLines(fv, Encoding.GetEncoding(1257));
int ilgis = 0;
nr = 0;
int nreil = 0;
foreach (string line in lines)
{
if (line.Length > ilgis)
{
ilgis = line.Length;
nr = nreil;
}
nreil++;
}
}
static void Print(string fv, string fvr, int nr)
{
string[] lines = File.ReadAllLines(fv, Encoding.GetEncoding(1257));
int nreil = 0;
using (var fr = File.CreateText(fvr))
{
foreach (string line in lines)
{
if (nr != nreil)
{
fr.WriteLine(line);
}
nreil++;
}
}
}
}
}