1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Rep Power

    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. #2
  3. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Rep Power
    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.

IMN logo majestic logo threadwatch logo seochat tools logo