Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Skip current line in file

Skip current line in file

Scheduled Pinned Locked Moved C#
database
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vanikanc
    wrote on last edited by
    #1

    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!

    R J P 3 Replies Last reply
    0
    • V vanikanc

      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!

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      Very simplistic, but something along the lines of:

      if (line.Contains("ACCEPT"))
      // Do something.
      else
      // Do something else

      Just 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

      1 Reply Last reply
      0
      • V vanikanc

        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!

        J Offline
        J Offline
        Jibesh
        wrote on last edited by
        #3

        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

        V 1 Reply Last reply
        0
        • J Jibesh

          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

          V Offline
          V Offline
          vanikanc
          wrote on last edited by
          #4

          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?

          J 1 Reply Last reply
          0
          • V vanikanc

            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?

            J Offline
            J Offline
            Jibesh
            wrote on last edited by
            #5

            arr... my bad, remove the null checking.. i modified the sample.

            Jibesh V P

            1 Reply Last reply
            0
            • V vanikanc

              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!

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Load them all into a staging table and only process the ones you want from there.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups