Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have text file with 1000 of lines and i have a date for every line by using date i want to fetch that line and should display the last words in datagridview windows forms.
For ex:-my text like

2017/07/22 4:50 records inserted --------- 20
2017/07/20 5:55 records inserted --------- 15
2017/07/23 2:30 records inserted --------- 29

when i enter a date it want to display the record for that day

What I have tried:

when i enter a date it want to display the record for that day
Posted
Updated 27-Jul-17 0:46am

C#
string text = "2017/07/22 4:50 records inserted --------- 20\n2017 / 07 / 20 5:55 records inserted ---------15\r\n2017 / 07 / 23 2:30 records inserted ---------29\r";
var lines = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
 
Share this answer
 
Comments
Member 11416690 31-Jul-17 4:55am    
yaa you said right,but i have 10000 records in a text file.so i can't pass the string like what u said.so,Is there any way
Graeme_Grant 31-Jul-17 5:00am    
Read and write in chunks and you can process very quickly. Ideally, you would be better off importing into a db like SQLite.
You can rad a text file line-by-line using below code and writ your logic to read last word.
string line;

// Read the file and display it line by line.
System.IO.StreamReader file = 
   new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
   string lastWord = line.Split(' ').Last();
}

file.Close();


If you do not have LINQ or do not want to use, below is the code..
string[] parts = line.Split(' ');
     string lastWord = parts[parts.Length - 1];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900