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. Handling Text data taken from file

Handling Text data taken from file

Scheduled Pinned Locked Moved C#
helpquestioncsharptutoriallearning
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.
  • R Offline
    R Offline
    rsaint27
    wrote on last edited by
    #1

    Hello, I'm doing some free-time programming with learning objective (in c#), and one of my "projects" led me to separate data taken from a text file. Opening and retrieving data is no problem, I just put it into a ArrayList of string element for now. But when I want to separate the data from that ArrayList, the only solution I've come up with is as 'ugly' as this one: ArrayList stream = new ArrayList(); (some code here) foreach (string str in stream) { if (str.contains(some string)) { do something } else { if (str.contains(some other string)) { do other thing } else { (... even more if's) } } } I think there should be another way to do this, specially without so much "contains" operations that are time consuming. Can you give me some directions on how to break such items apart? I'm thinking this could also be used in other areas like socket communication. This feels like a very dumb question to me, but if I don't ask, I'll never learn. Thanks for any help you can give me.

    A 1 Reply Last reply
    0
    • R rsaint27

      Hello, I'm doing some free-time programming with learning objective (in c#), and one of my "projects" led me to separate data taken from a text file. Opening and retrieving data is no problem, I just put it into a ArrayList of string element for now. But when I want to separate the data from that ArrayList, the only solution I've come up with is as 'ugly' as this one: ArrayList stream = new ArrayList(); (some code here) foreach (string str in stream) { if (str.contains(some string)) { do something } else { if (str.contains(some other string)) { do other thing } else { (... even more if's) } } } I think there should be another way to do this, specially without so much "contains" operations that are time consuming. Can you give me some directions on how to break such items apart? I'm thinking this could also be used in other areas like socket communication. This feels like a very dumb question to me, but if I don't ask, I'll never learn. Thanks for any help you can give me.

      A Offline
      A Offline
      Andrei Ungureanu
      wrote on last edited by
      #2

      Try using a List<string> template instead of an ArrayList. This class has a FindAll method that you could find to be helpful. Hope it helps.

      Do your best to be the best

      R 1 Reply Last reply
      0
      • A Andrei Ungureanu

        Try using a List<string> template instead of an ArrayList. This class has a FindAll method that you could find to be helpful. Hope it helps.

        Do your best to be the best

        R Offline
        R Offline
        rsaint27
        wrote on last edited by
        #3

        It's a good sugestion, especially with the use of a "Predicate" in the search field. However, now I've got a new question... ;) Is it possible with .net 2.0 to get a range of data between known delimiters using predicate's? This would be soooo much cleaner. Thanks for the hint.

        A 1 Reply Last reply
        0
        • R rsaint27

          It's a good sugestion, especially with the use of a "Predicate" in the search field. However, now I've got a new question... ;) Is it possible with .net 2.0 to get a range of data between known delimiters using predicate's? This would be soooo much cleaner. Thanks for the hint.

          A Offline
          A Offline
          Andrei Ungureanu
          wrote on last edited by
          #4

          I don't want to be rude, but take a look in Visual Studio's Help - MSDN, you'll get most of your answers there.

          rsaint27 wrote:

          Is it possible with .net 2.0 to get a range of data between known delimiters using predicate's?

          I suppose you have seen that the FindAll method retuns a List<list>, so you can call the list's GetRange method...;)...would that help?

          Do your best to be the best

          R 1 Reply Last reply
          0
          • A Andrei Ungureanu

            I don't want to be rude, but take a look in Visual Studio's Help - MSDN, you'll get most of your answers there.

            rsaint27 wrote:

            Is it possible with .net 2.0 to get a range of data between known delimiters using predicate's?

            I suppose you have seen that the FindAll method retuns a List<list>, so you can call the list's GetRange method...;)...would that help?

            Do your best to be the best

            R Offline
            R Offline
            rsaint27
            wrote on last edited by
            #5

            Thanks again for your help, And :sigh: :-O I'll look better in reference documentation before posting here.

            A 1 Reply Last reply
            0
            • R rsaint27

              Thanks again for your help, And :sigh: :-O I'll look better in reference documentation before posting here.

              A Offline
              A Offline
              Andrei Ungureanu
              wrote on last edited by
              #6

              Try it...it doesn't hurt

              Do your best to be the best

              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