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. Array of Strings....

Array of Strings....

Scheduled Pinned Locked Moved C#
questionhardwaredata-structures
20 Posts 5 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.
  • P Pete OHanlon

    Really that simple. Of course, there's a lot more you can do with the list, but that's enough to get you going.

    *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

    "Mind bleach! Send me mind bleach!" - Nagy Vilmos

    CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

    G Offline
    G Offline
    glennPattonWork3
    wrote on last edited by
    #7

    Cool, I have also found "http://www.codeproject.com/Articles/38447/Generic-List-C">Generic List (C#) Looks like that is my afternoon sorted! Glenn

    1 Reply Last reply
    0
    • G glennPattonWork3

      Hi All, I am writing a program to download some data off a piece of hardware. My thinking was have an array fill it. The data is in the form of strings rather than ints (which have done this with in the past) my question is strings are bigger than ints so will this cause issues with overflow and what is the correct way of handling groups of strings?? Glenn

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

      Yes a List, or a Queue if you want to have one thread adding values and another processing them. :thumbsup:

      glennPattonWork wrote:

      strings rather than ints

      If they are ints that have been stringified, then why not Parse them and then add them to the collection?

      G 1 Reply Last reply
      0
      • P PIEBALDconsult

        Yes a List, or a Queue if you want to have one thread adding values and another processing them. :thumbsup:

        glennPattonWork wrote:

        strings rather than ints

        If they are ints that have been stringified, then why not Parse them and then add them to the collection?

        G Offline
        G Offline
        glennPattonWork3
        wrote on last edited by
        #9

        Good, These are strings, I meant I had used an integer array to store the data as it came in. I was thinking that as Strings are bigger in size I didn't want to slow everything down by trying to handle a load of them as an array, (seemed to me like having one huge box containing smaller boxes rather unwieldy!) Glenn

        P 1 Reply Last reply
        0
        • G glennPattonWork3

          Good, These are strings, I meant I had used an integer array to store the data as it came in. I was thinking that as Strings are bigger in size I didn't want to slow everything down by trying to handle a load of them as an array, (seemed to me like having one huge box containing smaller boxes rather unwieldy!) Glenn

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #10

          The alternative, as noted in this part of the thread, is to use a Queue so you could remove items when you are finished processing them - this helps to keep things down to a more managable size.

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          1 Reply Last reply
          0
          • P Pete OHanlon

            Really that simple. Of course, there's a lot more you can do with the list, but that's enough to get you going.

            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            J Offline
            J Offline
            JosephvObrien
            wrote on last edited by
            #11

            It can insert multiple values or characters in your program. Array of string is the best way to insert multiple character to take at a time with the help of strings. Most of string start from zero. Three kind of strings are there : one pair string,two pair string and multiple pair string.

            P 1 Reply Last reply
            0
            • J JosephvObrien

              It can insert multiple values or characters in your program. Array of string is the best way to insert multiple character to take at a time with the help of strings. Most of string start from zero. Three kind of strings are there : one pair string,two pair string and multiple pair string.

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #12

              Are you really sure you meant to reply to me? The OP doesn't get notified if you post an answer to my posts.

              *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

              "Mind bleach! Send me mind bleach!" - Nagy Vilmos

              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

              1 Reply Last reply
              0
              • G glennPattonWork3

                Hi All, I am writing a program to download some data off a piece of hardware. My thinking was have an array fill it. The data is in the form of strings rather than ints (which have done this with in the past) my question is strings are bigger than ints so will this cause issues with overflow and what is the correct way of handling groups of strings?? Glenn

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #13

                While text (strings) may be a good way to transfer information between systems, it is not the recommended way to store data in memory. So my approach would be slightly different, I'd have: - a textual representation of the data, as an example X123Y456E would be a point with X and Y coordinates (E stands for a terminator, think newline character); - a class that holds an instance of data, in the example:

                public class MyPoint {
                public int X;
                public int Y;
                }

                BTW: I prefer a class over a struct to avoid all kinds of problems including boxing/unboxing. - some container that holds all the data, this could be List<MyPoint> myCollectionOfPoints in the example. - a method to receive textual data, convert it on the spot, and store it; it might look like:

                public void ReceiveMyPoint() {
                string line=mySerialPort.ReadLine(); // this is why newline is a good terminator!
                ... here comes input validation and parsing, resulting in actual values:
                int x=...;
                int y=...;
                myCollectionOfPoints.Add(new MyPoint(x,y));
                }

                - a thread to consume all incoming data, basically a loop calling ReceiveMyPoint() all the time. I don't use the DataReceived event here, as that does not synchronize with incoming text lines, it fires randomly when "some data" is available, which may well be a partial line of text. The net result is your interface is textual, the data is in meaningful types (two ints in the example), conversion is not a separate step, and no storage space gets wasted. Note: you must program defensively when receiving data from another system, as it will go wrong sooner or later, with a bad conenction, some missing characters, a noisy line, whatever. Therefore validation is important; even the simplest checksum or CRC added to each message would prove valuable. :)

                Luc Pattyn [My Articles] Nil Volentibus Arduum

                G 2 Replies Last reply
                0
                • L Luc Pattyn

                  While text (strings) may be a good way to transfer information between systems, it is not the recommended way to store data in memory. So my approach would be slightly different, I'd have: - a textual representation of the data, as an example X123Y456E would be a point with X and Y coordinates (E stands for a terminator, think newline character); - a class that holds an instance of data, in the example:

                  public class MyPoint {
                  public int X;
                  public int Y;
                  }

                  BTW: I prefer a class over a struct to avoid all kinds of problems including boxing/unboxing. - some container that holds all the data, this could be List<MyPoint> myCollectionOfPoints in the example. - a method to receive textual data, convert it on the spot, and store it; it might look like:

                  public void ReceiveMyPoint() {
                  string line=mySerialPort.ReadLine(); // this is why newline is a good terminator!
                  ... here comes input validation and parsing, resulting in actual values:
                  int x=...;
                  int y=...;
                  myCollectionOfPoints.Add(new MyPoint(x,y));
                  }

                  - a thread to consume all incoming data, basically a loop calling ReceiveMyPoint() all the time. I don't use the DataReceived event here, as that does not synchronize with incoming text lines, it fires randomly when "some data" is available, which may well be a partial line of text. The net result is your interface is textual, the data is in meaningful types (two ints in the example), conversion is not a separate step, and no storage space gets wasted. Note: you must program defensively when receiving data from another system, as it will go wrong sooner or later, with a bad conenction, some missing characters, a noisy line, whatever. Therefore validation is important; even the simplest checksum or CRC added to each message would prove valuable. :)

                  Luc Pattyn [My Articles] Nil Volentibus Arduum

                  G Offline
                  G Offline
                  glennPattonWork3
                  wrote on last edited by
                  #14

                  Great thanks for that, can you recommend a reference for this type of data handling (or really any data handling would be useful) It's just I am tasked with writing an application to interface to a board that does exist (yet!) "it will do it like the X board, you already written the software for that". I'm looking at this as a chance to increase my Windows knowledge! Glenn

                  L 1 Reply Last reply
                  0
                  • G glennPattonWork3

                    Great thanks for that, can you recommend a reference for this type of data handling (or really any data handling would be useful) It's just I am tasked with writing an application to interface to a board that does exist (yet!) "it will do it like the X board, you already written the software for that". I'm looking at this as a chance to increase my Windows knowledge! Glenn

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #15

                    Sorry, no reference, just my own experience with peripherals and embedded systems. :)

                    Luc Pattyn [My Articles] Nil Volentibus Arduum

                    G 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Sorry, no reference, just my own experience with peripherals and embedded systems. :)

                      Luc Pattyn [My Articles] Nil Volentibus Arduum

                      G Offline
                      G Offline
                      glennPattonWork3
                      wrote on last edited by
                      #16

                      Ah well google & MSDN, I did look at something on the code project that confused me! (link earlier) Glenn

                      1 Reply Last reply
                      0
                      • L Luc Pattyn

                        While text (strings) may be a good way to transfer information between systems, it is not the recommended way to store data in memory. So my approach would be slightly different, I'd have: - a textual representation of the data, as an example X123Y456E would be a point with X and Y coordinates (E stands for a terminator, think newline character); - a class that holds an instance of data, in the example:

                        public class MyPoint {
                        public int X;
                        public int Y;
                        }

                        BTW: I prefer a class over a struct to avoid all kinds of problems including boxing/unboxing. - some container that holds all the data, this could be List<MyPoint> myCollectionOfPoints in the example. - a method to receive textual data, convert it on the spot, and store it; it might look like:

                        public void ReceiveMyPoint() {
                        string line=mySerialPort.ReadLine(); // this is why newline is a good terminator!
                        ... here comes input validation and parsing, resulting in actual values:
                        int x=...;
                        int y=...;
                        myCollectionOfPoints.Add(new MyPoint(x,y));
                        }

                        - a thread to consume all incoming data, basically a loop calling ReceiveMyPoint() all the time. I don't use the DataReceived event here, as that does not synchronize with incoming text lines, it fires randomly when "some data" is available, which may well be a partial line of text. The net result is your interface is textual, the data is in meaningful types (two ints in the example), conversion is not a separate step, and no storage space gets wasted. Note: you must program defensively when receiving data from another system, as it will go wrong sooner or later, with a bad conenction, some missing characters, a noisy line, whatever. Therefore validation is important; even the simplest checksum or CRC added to each message would prove valuable. :)

                        Luc Pattyn [My Articles] Nil Volentibus Arduum

                        G Offline
                        G Offline
                        glennPattonWork3
                        wrote on last edited by
                        #17

                        Thanks for the Help! I now have it getting the data tomorrow I can work on it further,but now have the bones. Glenn

                        1 Reply Last reply
                        0
                        • P Pete OHanlon

                          First of all, why an array? Why not a List of strings? Second, are the strings unique or are they just a well defined list that you could get some combination of? If it's a well known list, just assign an enumeration to the strings and return a list of those enumerations. Alternatively, you could write a slightly more complex algorithm and use a Dictionary to keep the string, and a list of indexes where that string occur - and then decode this at the client end.

                          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                          G Offline
                          G Offline
                          glennPattonWork3
                          wrote on last edited by
                          #18

                          Thanks for the Help! I now have it getting the data tomorrow I can work on it further,but now have the bones. Glenn

                          P 1 Reply Last reply
                          0
                          • G glennPattonWork3

                            Thanks for the Help! I now have it getting the data tomorrow I can work on it further,but now have the bones. Glenn

                            P Offline
                            P Offline
                            Pete OHanlon
                            wrote on last edited by
                            #19

                            You're welcome. I look forward to finding out how you get on.

                            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                            G 1 Reply Last reply
                            0
                            • P Pete OHanlon

                              You're welcome. I look forward to finding out how you get on.

                              *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                              "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                              G Offline
                              G Offline
                              glennPattonWork3
                              wrote on last edited by
                              #20

                              You are not the only one, it would easier if I had more direction than oh it work like X when X is not fully tested and the board you are writing the code for does not exist yet, but to keep the powers that be happy (Gannt charts running) "The Windows Interface Code Must Be Started:". Will let you know! Glenn (Dilbert anyone??)

                              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