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. Char Arrays and strings

Char Arrays and strings

Scheduled Pinned Locked Moved C#
helpdata-structuresquestion
5 Posts 4 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.
  • F Offline
    F Offline
    ffowler
    wrote on last edited by
    #1

    Hello All, Was only hoping for some direction as to a problem I am trying to figure out. I have an array of characters and for this purpose the characters are ABC|C|D|E|F|G|H|I|JKL|...|XYZ| Here is the issue: I want to find ABC| so that I could read everything after is until I get to JKL|. And then again until I get to XYZ|. Since each char is separately enumerated in the array, is there a way that I could check for the above mentioned string of chars? I have tried but I keep getting stopped and the one that looked liked it worked... well... was so convoluted, I didn't understand what I did after I wrote it. Any bone thrown this way would be greatly appreciated.

    C E realJSOPR 3 Replies Last reply
    0
    • F ffowler

      Hello All, Was only hoping for some direction as to a problem I am trying to figure out. I have an array of characters and for this purpose the characters are ABC|C|D|E|F|G|H|I|JKL|...|XYZ| Here is the issue: I want to find ABC| so that I could read everything after is until I get to JKL|. And then again until I get to XYZ|. Since each char is separately enumerated in the array, is there a way that I could check for the above mentioned string of chars? I have tried but I keep getting stopped and the one that looked liked it worked... well... was so convoluted, I didn't understand what I did after I wrote it. Any bone thrown this way would be greatly appreciated.

      C Offline
      C Offline
      carbon_golem
      wrote on last edited by
      #2

      If you're doing this in an array of characters and not a string, then I think I would implement a string method to do pretty much the same thing as the string class but on a char array. Then your searching may become somewhat easier. So... IndexOf("ABC") IndexOf("JKL") and grab what you need to based on those indexes. Scott P

      “It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.” -Edsger Dijkstra

      1 Reply Last reply
      0
      • F ffowler

        Hello All, Was only hoping for some direction as to a problem I am trying to figure out. I have an array of characters and for this purpose the characters are ABC|C|D|E|F|G|H|I|JKL|...|XYZ| Here is the issue: I want to find ABC| so that I could read everything after is until I get to JKL|. And then again until I get to XYZ|. Since each char is separately enumerated in the array, is there a way that I could check for the above mentioned string of chars? I have tried but I keep getting stopped and the one that looked liked it worked... well... was so convoluted, I didn't understand what I did after I wrote it. Any bone thrown this way would be greatly appreciated.

        E Offline
        E Offline
        engsrini
        wrote on last edited by
        #3

        wat u trying to achieve here? r u trying read the characters in between the two known string (ABC & JKL) by the way how come the strings ("ABC" AND "JKL") got stored in char array. if all of them are stored in char array, you can form these lettere by just appending them (upto 3 char) and compare it with Known string (ABC OR JKL)

        F 1 Reply Last reply
        0
        • E engsrini

          wat u trying to achieve here? r u trying read the characters in between the two known string (ABC & JKL) by the way how come the strings ("ABC" AND "JKL") got stored in char array. if all of them are stored in char array, you can form these lettere by just appending them (upto 3 char) and compare it with Known string (ABC OR JKL)

          F Offline
          F Offline
          ffowler
          wrote on last edited by
          #4

          Thank you carbon_golem for your response. Srini,

          srini wrote:

          wat u trying to achieve here? r u trying read the characters in between the two known string (ABC & JKL)

          Yes I am. Let's say I want to write what is between ABC and JKL to a file and then write what's in between JKL and XYZ to the same file. I can almost see what you are getting at. May I be so bold as to ask if you could expand on it a little bit more. Also:

          srini wrote:

          by the way how come the strings ("ABC" AND "JKL") got stored in char array.

          I was just giving a clear example

          1 Reply Last reply
          0
          • F ffowler

            Hello All, Was only hoping for some direction as to a problem I am trying to figure out. I have an array of characters and for this purpose the characters are ABC|C|D|E|F|G|H|I|JKL|...|XYZ| Here is the issue: I want to find ABC| so that I could read everything after is until I get to JKL|. And then again until I get to XYZ|. Since each char is separately enumerated in the array, is there a way that I could check for the above mentioned string of chars? I have tried but I keep getting stopped and the one that looked liked it worked... well... was so convoluted, I didn't understand what I did after I wrote it. Any bone thrown this way would be greatly appreciated.

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            You could use this:

            string[] parts = mystring.Split('|');

            Then, you could iterate through the string array (parts) to get your values. BTW, you probably don't want to end your string with a "|" character.

            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            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