Skip current line in file
-
Hi, It is never easy!! We have a response file which has two types of decisions, ACCEPT and DECLINE with in the comma separated name/value pair. I am inserting this information in to the database and want only the decision ACCEPT. In cases in line contains DECLINE, I want to skip this current line and go to the next line. I am using the StreamREader to read the file. Thanks!
-
Hi, It is never easy!! We have a response file which has two types of decisions, ACCEPT and DECLINE with in the comma separated name/value pair. I am inserting this information in to the database and want only the decision ACCEPT. In cases in line contains DECLINE, I want to skip this current line and go to the next line. I am using the StreamREader to read the file. Thanks!
Very simplistic, but something along the lines of:
if (line.Contains("ACCEPT"))
// Do something.
else
// Do something elseJust some pseudo code but that might set you off in the right direction. Might have been useful to see some code.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me
-
Hi, It is never easy!! We have a response file which has two types of decisions, ACCEPT and DECLINE with in the comma separated name/value pair. I am inserting this information in to the database and want only the decision ACCEPT. In cases in line contains DECLINE, I want to skip this current line and go to the next line. I am using the StreamREader to read the file. Thanks!
try something like this.
using (StreamReader sr = new StreamReader(path))
{
while (sr.Peek() > -1)
{
string line = sr.ReadLine();
//extract the line contents
if( line.Contains("Accept")) // you can replace the condition with your choice
{
//Do Insert to database
}
}
}Jibesh V P
-
try something like this.
using (StreamReader sr = new StreamReader(path))
{
while (sr.Peek() > -1)
{
string line = sr.ReadLine();
//extract the line contents
if( line.Contains("Accept")) // you can replace the condition with your choice
{
//Do Insert to database
}
}
}Jibesh V P
-
Thanks! Line.Contains("ACCEPT") worked perfect!! Wanted to find out, since you are already doing a PEEK, why are you still checking to see of the line is NULL?
-
Hi, It is never easy!! We have a response file which has two types of decisions, ACCEPT and DECLINE with in the comma separated name/value pair. I am inserting this information in to the database and want only the decision ACCEPT. In cases in line contains DECLINE, I want to skip this current line and go to the next line. I am using the StreamREader to read the file. Thanks!
Load them all into a staging table and only process the ones you want from there.