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