|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
breaking up a string
What is the proper way to break up a string and get what you need out of it?
This is what I have... I read a string in, say "blue 4 5". What I want to be able to do is compare the first part of the string, blue, to blue. If they are equal, I need to read the last part, 4 5, in as a date. There is a lot more to this, but I am curious as to how to break up the string. What I think I need to do is read the string in, blue 4 5. Use a for loop to read the first 5 letters. Append those first 5 letters to a string, and compare that string to "blue ". If they are equal, I use a for loop starting with index 6 and ending with 8, and read in the date. I then send that date to my queue. Am I doing this right? Is there an easier way to break up the string? Thanks for the help. |
|
#2
|
||||
|
||||
|
There are several functions that may be useful to you...
strtok() - Find the next token in a string. You could use that to find the spaces in the string to separate it into individual substrings. strspn() - Find the first substring. You could use this to find a substring in another string. It all depends on what you are trying to do. It seems to me that your specific case could allow you to write your own string searching function, like you said, which would be fastest.
__________________
Jason Doucette / Xona.com™ - Programming Windows Errata Addendum "Discussion is an exchange of knowledge; argument is an exchange of ignorance." |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > breaking up a string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|