Search
 
SCRIPT & CODE EXAMPLE
 

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();
Comment

PREVIOUS NEXT
Code Example
Csharp :: custom player spawner mirror 
Csharp :: quine in c# 
Csharp :: c# ef dynamic ApplyConfiguration 
Csharp :: music file explorer c# 
Csharp :: c# delegates 
Csharp :: How to truncate a decimal without rounding 
Csharp :: unity exenerate 
Csharp :: c sharp Enum class 
Csharp :: how to extract unique years from a list of different years in c# 
Csharp :: Showing a hidden WPF window 
Csharp :: unity move in x seconds to pos 
Csharp :: asp.net issue 
Csharp :: mvc validate 
Csharp :: who is dani? game dev 
Csharp :: c# expression func automatically select return type 
Csharp :: c# using rename class 
Csharp :: show in editor unity 
Csharp :: ascii art american flag 
Csharp :: tempdata serializer cannot erorr 
Csharp :: virtual properties and lazy loading in c# 
Csharp :: difference between all logging framework .NET Core? 
Csharp :: number to string ef example c# 
Csharp :: c# unhandled exception in thread” 
Csharp :: c# convert 1 to 01 
Csharp :: asp.net razor get list without refresh 
Csharp :: Hangfire Creation Table With EFCore 
Csharp :: dfgf 
Csharp :: Align String with Spaces [C#] 
Csharp :: isdaylightsavingtime in c# 
Csharp :: create star rating using loop in c# 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =