Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Last N lines from file

string filename = @"c:	est.txt";
int numberoflines = 10;
StreamReader reader = new StreamReader(); //pick appropriate Encoding
reader.BaseStream.Seek(0, SeekOrigin.End);
int count = 0;
while ((count < numberoflines) && (reader.BaseStream.Position > 0))
{
    reader.BaseStream.Position--;
    int c = reader.BaseStream.ReadByte();
    if (reader.BaseStream.Position > 0)
        reader.BaseStream.Position--;
    if (c == Convert.ToInt32('
'))
    {
        ++count;
    }
}
string str = reader.ReadToEnd();
string[] arr = str.Replace("
", "").Split('
');
reader.Close();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Last #N #lines #file
ADD COMMENT
Topic
Name
2+5 =