CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: strings

  1. #1
    Join Date
    Oct 2001
    Posts
    745

    strings

    Hi,

    I have a string like this as follows:

    const char* Text = "CZARIUC=CHS,IND,e:\tools\rs\300\test,"

    I want to take the string part,which is coming before The "=" Sign.ie: only CZARIUC.

    How Can I do that?

    Thanks in Advance..

  2. #2
    Join Date
    Nov 1999
    Location
    Copenhagen, Denmark
    Posts
    265
    MSDN:

    strtok, wcstok
    Find the next token in a string.

    Routine Required Header
    strtok <string.h>
    wcstok <string.h>


    char *strtok( char *strToken, const char *strDelimit );
    wchar_t *wcstok( wchar_t *strToken, const wchar_t *strDelimit );
    Parameters
    strToken
    String containing token(s)
    strDelimit
    Set of delimiter characters
    Libraries
    All versions of the C run-time libraries.

    Return Value
    All of these functions return a pointer to the next token found in strToken. They return NULL when no more tokens are found. Each call modifies strToken by substituting a NULL character for each delimiter that is encountered.

    Remarks
    The strtok function finds the next token in strToken. The set of characters in strDelimit specifies possible delimiters of the token to be found in strToken on the current call. wcstok is the wide-character version of strtok. The arguments and return value of wcstok are wide-character strings. These two functions behave identically otherwise.

    Generic-Text Routine Mappings
    TCHAR.H Routine _UNICODE Defined
    _tcstok wcstok


    On the first call to strtok, the function skips leading delimiters and returns a pointer to the first token in strToken, terminating the token with a null character. More tokens can be broken out of the remainder of strToken by a series of calls to strtok. Each call to strtok modifies strToken by inserting a null character after the token returned by that call. To read the next token from strToken, call strtok with a NULL value for the strToken argument. The NULL strToken argument causes strtok to search for the next token in the modified strToken. The strDelimit argument can take any value from one call to the next so that the set of delimiters may vary.

    Warning Each of these functions uses a static variable for parsing the string into tokens. If multiple or simultaneous calls are made to the same function, a high potential for data corruption and inaccurate results exists. Therefore, do not attempt to call the same function simultaneously for different strings and be aware of calling one of these functions from within a loop where another routine may be called that uses the same function. However, calling this function simultaneously from multiple threads does not have undesirable effects.

    Example
    /* STRTOK.C: In this program, a loop uses strtok
    * to print all the tokens (separated by commas
    * or blanks) in the string named "string".
    */

    #include <string.h>
    #include <stdio.h>

    char string[] = "A string\tof ,,tokens\nand some more tokens";
    char seps[] = " ,\t\n";
    char *token;

    void main( void )
    {
    printf( "%s\n\nTokens:\n", string );
    /* Establish string and get the first token: */
    token = strtok( string, seps );
    while( token != NULL )
    {
    /* While there are tokens in "string" */
    printf( " %s\n", token );
    /* Get next token: */
    token = strtok( NULL, seps );
    }
    }

    Output
    A string of ,,tokens
    and some more tokens

    Tokens:
    A
    string
    of
    tokens
    and
    some
    more
    tokens

    See Also
    strcspn

    Built on Wednesday, October 04, 2000
    --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources.
    Best regards,
    S. Bro

    "I would be happy to deal with my problems one at the time if they would only line up!"
    -Paul Cilwa, "Borland C++ Insider".

    Other useful fora some of which I ruthlessly clipboarded from other peoples footers.

    MSDN: http://search.microsoft.com/us/dev/default.asp
    WIN 32 Assembler: http://board.win32asmcommunity.net/
    RDBMS: http://www.dbforums.com
    Robert's Perl Tutorial: http://www.sthomas.net/roberts-perl-tutorial.htm
    Merriam-Webster Online: http://www.m-w.com/home.htm
    Writing Unmaintainable Code: http://mindprod.com/unmain.html

  3. #3
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    I hope this is a typo
    const char* Text = "CZARIUC=CHS,IND,e:\tools\rs\300\test,"
    It should be
    Code:
    const char* Text = "CZARIUC=CHS,IND,e:\\tools\\rs\\300\\test,"
    otherwise \t translates to tab and \r translates to return.
    Succinct is verbose for terse

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

Featured