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. More ArrayList problems.

More ArrayList problems.

Scheduled Pinned Locked Moved C#
helpdata-structurestutorialquestion
5 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.
  • S Offline
    S Offline
    scotlandc
    wrote on last edited by
    #1

    Hi, I have an ArrayList populated by a text file made up of lines comprising 3 columns: ID, Duration, Description. They roughly look like this 12345678.abc 020 This is a description 12345678.abd 030 This is another description etc The ID column is always 12 characters, the duration is always 3 numbers, the description obviously can change from line to line. Each line of the text file is read into the array in sequence, I need to be able to break each element of the ArrayList into the appropriate columns. The problem is with the description column as it contains multiple spaces. I can't work out how to break each string into the columns required Please can anyone help? Thank you very much in advance Scott

    I L 2 Replies Last reply
    0
    • S scotlandc

      Hi, I have an ArrayList populated by a text file made up of lines comprising 3 columns: ID, Duration, Description. They roughly look like this 12345678.abc 020 This is a description 12345678.abd 030 This is another description etc The ID column is always 12 characters, the duration is always 3 numbers, the description obviously can change from line to line. Each line of the text file is read into the array in sequence, I need to be able to break each element of the ArrayList into the appropriate columns. The problem is with the description column as it contains multiple spaces. I can't work out how to break each string into the columns required Please can anyone help? Thank you very much in advance Scott

      I Offline
      I Offline
      Insincere Dave
      wrote on last edited by
      #2

      If the format is as you described then using substring would probably be easiest. string s = "12345678.abc 020 This is a description"; string id = s.Substring(0, 12); string duration = s.Substring(13, 3); string description = s.Substring(17); You might want to put this in a catch block if there is a chance an line is incorrect. For more complex string manipulation you might want to look at regular expressions.

      S 1 Reply Last reply
      0
      • I Insincere Dave

        If the format is as you described then using substring would probably be easiest. string s = "12345678.abc 020 This is a description"; string id = s.Substring(0, 12); string duration = s.Substring(13, 3); string description = s.Substring(17); You might want to put this in a catch block if there is a chance an line is incorrect. For more complex string manipulation you might want to look at regular expressions.

        S Offline
        S Offline
        scotlandc
        wrote on last edited by
        #3

        Thank you for replying, I see where you're going with this. It does however raise another question in as much as I then need to bind those strings into a datagrid under the same headings. Any ideas how?

        I 1 Reply Last reply
        0
        • S scotlandc

          Thank you for replying, I see where you're going with this. It does however raise another question in as much as I then need to bind those strings into a datagrid under the same headings. Any ideas how?

          I Offline
          I Offline
          Insincere Dave
          wrote on last edited by
          #4

          Create a class to store the id,duration and description. Then create an arraylist with instances of that class instead of strings.

          1 Reply Last reply
          0
          • S scotlandc

            Hi, I have an ArrayList populated by a text file made up of lines comprising 3 columns: ID, Duration, Description. They roughly look like this 12345678.abc 020 This is a description 12345678.abd 030 This is another description etc The ID column is always 12 characters, the duration is always 3 numbers, the description obviously can change from line to line. Each line of the text file is read into the array in sequence, I need to be able to break each element of the ArrayList into the appropriate columns. The problem is with the description column as it contains multiple spaces. I can't work out how to break each string into the columns required Please can anyone help? Thank you very much in advance Scott

            L Offline
            L Offline
            lmoelleb
            wrote on last edited by
            #5

            Alternatively use Split - it has a parameter specifying the maximum number of strings in the array result.

            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