Split a String In C++

Discussion in 'C++' started by debapriya.patra, Apr 3, 2009.

  1. debapriya.patra

    debapriya.patra New Member

    Joined:
    Mar 25, 2009
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Hi All,

    Is there any function available to split a string.

    I wanted to split the strings based on the special characters like (-,_!,@,#,^,).

    I am poor in C++ but in java i used to do it using StringTokenizer.


    Say anybody already worked on such problems can help oot on this....

    I need help bcz i don't know C++ , i am learning now.


    Thanks in advance

    Regards,
    Deba
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
  3. debapriya.patra

    debapriya.patra New Member

    Joined:
    Mar 25, 2009
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    In which header file i need to include to use this function and what is the parameters it required.??
     
  4. listendinesh

    listendinesh New Member

    Joined:
    Aug 3, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    string.h


    Example Code

    Code:
    char str[] = "now # is the time for all # good men to come to the # aid of
      their country";
         char delims[] = "#";
         char *result = NULL;
         result = strtok( str, delims );
         while( result != NULL ) {
             printf( "result is \"%s\"\n", result );
             result = strtok( NULL, delims );
         }
     
  5. debapriya.patra

    debapriya.patra New Member

    Joined:
    Mar 25, 2009
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    thanks a lot for the response....


    Anyway i got the same example from google and run that ..
    now its working for me...


    once again thanks.....
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice