Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Split a String In C++ (http://www.go4expert.com/forums/split-string-cpp-t16785/)

debapriya.patra 3Apr2009 13:02

Split a String In C++
 
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

xpi0t0s 3Apr2009 13:04

Re: Split a String In C++
 
strtok

debapriya.patra 3Apr2009 13:23

Re: Split a String In C++
 
In which header file i need to include to use this function and what is the parameters it required.??

listendinesh 3Apr2009 14:23

Re: Split a String In C++
 
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 );
    }


debapriya.patra 3Apr2009 16:10

Re: Split a String In C++
 
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.....


All times are GMT +5.5. The time now is 18:13.