Thread: question about parsing a string??

  1. #1
    Registered User
    Join Date
    Jul 2003

    question about parsing a string??


    I have a problem that I'm trying to figure out. I have the following string:


    but something1 needs to be stored into some string variable
    and something2 need to be stored into another seperate string variable. The : is just to seperate the 2 strings, it needs to be ignored.

    I am not at all sure if this can even be done, or if so how to do it??

    I am writing this in C++, but have not figured out how to parse this thing?

    Thanks for any help in advance. It is appreciated.

  2. #2
    Registered User
    Join Date
    Mar 2002
    There are several ways...
    char my_string[50] = "word"; //my_string
    char my_string2[50] = "hello"; //my_string2
    cin.getline(my_string, 50);
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    char * szString1 = szInput;
    char * szString2 = strchr(szInput, ':');
    if (szString2 != NULL) {
           *szString2 = '\0'; // Terminate string1 at :
           szString2++;       // Point to start of string2
    Assumes szInput can be modified.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  2. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  3. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  4. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM