hi guyes,
my need is to read the next line data and check the particular character(i.e ;) in that data from file when i read the current line
without consuming next line by streamreader();
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 5, 2013, 4:31 AM EDT
Can you provide your code?
Regards,
Iftikar
Mai Hu Na84 reputationPosted Jul 5, 2013, 5:18 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 5, 2013, 5:40 AM EDT
If the '; 'will only appear as the first character of a line, you could also use line.StartsWith(";").
Mai Hu Na84 reputationPosted Jul 7, 2013, 2:34 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 7, 2013, 5:12 AM EDT
10029365,20130701,dbt,ep,manfee
;MGFEE:Management Fee
OR
10029365,20130701,dbt,ep,manfee;MGFEE:Management Fee
Regards,
Iftikar
VulpesRank #55 · 29.2K reputationPosted Jul 7, 2013, 7:29 AM EDT
using (StreamReader sr = new StreamReader("atul.txt"))
{
int i;
int c = (int)';';
string line = null;
while ((i = sr.Peek()) > 0)
{
if (i == c) break;
line = sr.ReadLine();
// code to insert line data into database
}
}
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 7, 2013, 7:41 PM EDT
hi,
To do this you have to read whole file first using File.ReadAllText methods
try..
string text = System.IO.File.ReadAllText(@"D:\textfile.txt");
var allText = text.Split(new string[] { "\r\n" }, StringSplitOptions.None);
for (var i = 0; i <= allText.Count(); i++)
{
string line = allText[i];
string nextline = allText[i + 1]; // put here validation if it is not exceed the array limit.
//do your code.
}
hope this will help you.