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. Reading values from specified line from a text file [modified]

Reading values from specified line from a text file [modified]

Scheduled Pinned Locked Moved C#
csharptutorial
3 Posts 3 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.
  • C Offline
    C Offline
    cnr369
    wrote on last edited by
    #1

    Hi all, i am working as a software eng..let know that how to read values from a text file at specified location which the file consists of no of lines of code...moreover i want to code in c#.net for example.. 1 23.34 2 456.33 --- i want to read values below 1 n 2 as x,y values...so plz let me know how to do.. Thanks in advance... Regards, cnr.. -- modified at 1:26 Friday 11th August, 2006

    E F 2 Replies Last reply
    0
    • C cnr369

      Hi all, i am working as a software eng..let know that how to read values from a text file at specified location which the file consists of no of lines of code...moreover i want to code in c#.net for example.. 1 23.34 2 456.33 --- i want to read values below 1 n 2 as x,y values...so plz let me know how to do.. Thanks in advance... Regards, cnr.. -- modified at 1:26 Friday 11th August, 2006

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      Just discard any lines you don't want, I assume you want to read in the alternate lines. In this case something like which follows should work.

      // Open the StreamReader
      using (StreamReader sr = new StreamReader(filename))
      {
      // Loop until the EOF
      while(sr.Peek() != -1)
      {
      // Discard the odd lines
      sr.ReadLine();
      // Read in the even lines for processing
      string line = sr.ReadLine();
      // Process Line here
      }
      // Close stream
      sr.Close();
      }


      Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed

      1 Reply Last reply
      0
      • C cnr369

        Hi all, i am working as a software eng..let know that how to read values from a text file at specified location which the file consists of no of lines of code...moreover i want to code in c#.net for example.. 1 23.34 2 456.33 --- i want to read values below 1 n 2 as x,y values...so plz let me know how to do.. Thanks in advance... Regards, cnr.. -- modified at 1:26 Friday 11th August, 2006

        F Offline
        F Offline
        Filip van der Meeren
        wrote on last edited by
        #3

        XML or ini files ? The way you do it is not readable for any other programmer, if anyone want to edit your code or has to take over your project, they will have a hard time to learn what that file stands for ... In XML or ini you can at least comment (in your code, or in the text file itself).

        Don't you also love the code?

        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