0
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.
0
If you don't want to read the second line at all if it starts with a ';' then try this:
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
}
}
0
is you text file content in this format
10029365,20130701,dbt,ep,manfee
;MGFEE:Management Fee
OR
10029365,20130701,dbt,ep,manfee;MGFEE:Management Fee
Regards,
Iftikar
0
no
0
Something like this perhaps?
using (StreamReader sr = new StreamReader("somefile.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (line.Contains(";")) continue;
// code to insert line data into database
}
}
If the '; 'will only appear as the first character of a line, you could also use line.StartsWith(";").
0
line1 10029365,20130701,dbt,ep,manfee
line2 ;MGFEE:Management Fee
i need to check the secondline data and if contain ; charactor skip the line first otherwise insert into datatable.
0
Hi,
Can you provide your code?
Regards,
Iftikar