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. read file

read file

Scheduled Pinned Locked Moved C#
tutorialquestion
6 Posts 2 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.
  • T Offline
    T Offline
    tek 2009
    wrote on last edited by
    #1

    I would like to fill a class from a text file as struture: 1000, n, km 5 description and so on knowing that the two lines represents a line of Class then how to assign each value (1000, n ,...) for each variable in the class??? thank you in advance

    L 1 Reply Last reply
    0
    • T tek 2009

      I would like to fill a class from a text file as struture: 1000, n, km 5 description and so on knowing that the two lines represents a line of Class then how to assign each value (1000, n ,...) for each variable in the class??? thank you in advance

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Read the text file, parse the data, and add it to objects of your class. You can create your objects either by a constructor or by setters for specific properties. Which part of this are you having difficulty with?

      It's time for a new signature.

      T 1 Reply Last reply
      0
      • L Lost User

        Read the text file, parse the data, and add it to objects of your class. You can create your objects either by a constructor or by setters for specific properties. Which part of this are you having difficulty with?

        It's time for a new signature.

        T Offline
        T Offline
        tek 2009
        wrote on last edited by
        #3

        in the parse the data where I have the problem, I used to read the file:

        string[] lines = System.IO.File.ReadAllLines(@"file.txt");

                foreach (string line in lines)
                {
                    Console.WriteLine("\\t" + line);
                }
        
        L 1 Reply Last reply
        0
        • T tek 2009

          in the parse the data where I have the problem, I used to read the file:

          string[] lines = System.IO.File.ReadAllLines(@"file.txt");

                  foreach (string line in lines)
                  {
                      Console.WriteLine("\\t" + line);
                  }
          
          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Well that's very interesting but what is the problem?

          It's time for a new signature.

          T 1 Reply Last reply
          0
          • L Lost User

            Well that's very interesting but what is the problem?

            It's time for a new signature.

            T Offline
            T Offline
            tek 2009
            wrote on last edited by
            #5

            i d'ont know how to parse the data from de file line by line, if you can complete the code , thank you

            L 1 Reply Last reply
            0
            • T tek 2009

              i d'ont know how to parse the data from de file line by line, if you can complete the code , thank you

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              tek 2009 wrote:

              i d'ont know how to parse the data from de file line by line, if you can complete the code , thank you

              Good try, but we are not here to write your programs for you. Take a look at the System.String[^] class and make use of some of its methods to get the results you are looking for. If you really don't know how to get started then try working through this book[^] which contains lots of useful tutorials.

              It's time for a new signature.

              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