Results 1 to 3 of 3

Thread: splitting a string up

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    splitting a string up

    is there a split function in c++?

    e.g

    _fstrcpy(data, split(data,1) );

    or something, im not sure,

    so if the var is

    char Word[50] = "Hello im a programmer"

    i want to try and split Word by the spaces, so split Word 2 maybe gives 'im' ?

  2. #2
    Addicted Member SpS's Avatar
    Join Date
    Jul 2005
    Posts
    201

    Re: splitting a string up

    make use of find_first_of
    Last edited by SpS; Jan 17th, 2006 at 11:13 PM.
    #Appreciate others by rating good posts !!

    #The Software Peter Principle is in operation when unwise developers "improve" and "generalize" the software until they themselves can no longer understand it, then the project slowly dies.

    #People who are still ignorant of their ignorance are dangerous.

  3. #3
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: splitting a string up

    Here you go try this

    #include <iostream>
    #include <cstring>
    #include <cstdlib>

    using namespace std;

    int main()
    {
    char str[] = "Hello; im; a; programmer;";
    char *StrPtr = NULL;
    StrPtr = strtok( str, ";" );
    while( StrPtr != NULL ) {
    cout << StrPtr << endl;
    StrPtr = strtok ( NULL, ";" );
    }
    system("PAUSE");
    return 0;
    }
    When your dreams come true.
    On error resume pulling hair out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width