Results 1 to 4 of 4

Thread: InStr

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

    InStr

    Again !

    This time i need the code for InStr in either C++ or Vb functions using the CString class.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    See my other post for why you shouldn't use CString
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Megatron
    Guest
    Use the StrChr function.

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    The strchr function finds only a character in a strin. To find a substring of a string use the strstr function

    MSDN Info
    Code:
    strstr, wcsstr, _mbsstr
    Find a substring.
    
    char *strstr( const char *string, const char *strCharSet );
    
    wchar_t *wcsstr( const wchar_t *string, const wchar_t *strCharSet );
    
    unsigned char *_mbsstr( const unsigned char *string, const unsigned char *strCharSet );
    
    Routine Required Header Compatibility 
    strstr <string.h> ANSI, Win 95, Win NT 
    wcsstr <string.h> or <wchar.h> ANSI, Win 95, Win NT 
    _mbsstr <mbstring.h> Win 95, Win NT 
    
    
    For additional compatibility information, see Compatibility in the Introduction.
    
    Libraries
    
    LIBC.LIB Single thread static library, retail version 
    LIBCMT.LIB Multithread static library, retail version 
    MSVCRT.LIB Import library for MSVCRT.DLL, retail version 
    
    
    Return Value
    
    Each of these functions returns a pointer to the first occurrence of strCharSet in string, or NULL if strCharSet does not appear in string. If strCharSet points to a string of zero length, the function returns string.
    
    Parameters
    
    string
    
    Null-terminated string to search
    
    strCharSet
    
    Null-terminated string to search for
    
    Remarks
    
    The strstr function returns a pointer to the first occurrence of strCharSet in string. The search does not include terminating null characters. wcsstr and _mbsstr are wide-character and multibyte-character versions of strstr. The arguments and return value of wcsstr are wide-character strings; those of _mbsstr are multibyte-character strings. These three functions behave identically otherwise.

    MSDN Example
    Code:
    Example
    
    /* STRSTR.C */
    
    #include <string.h>
    #include <stdio.h>
    
    char str[] =    "lazy";
    char string[] = "The quick brown dog jumps over the lazy fox";
    char fmt1[] =   "         1         2         3         4         5";
    char fmt2[] =   "12345678901234567890123456789012345678901234567890";
    
    void main( void )
    {
       char *pdest;
       int  result;
       printf( "String to be searched:\n\t%s\n", string );
       printf( "\t%s\n\t%s\n\n", fmt1, fmt2 );
       pdest = strstr( string, str );
       result = pdest - string + 1;
       if( pdest != NULL )
          printf( "%s found at position %d\n\n", str, result );
       else
          printf( "%s not found\n", str );
    }
    
    
    Output
    
    String to be searched:
       The quick brown dog jumps over the lazy fox
                1         2         3         4         5
       12345678901234567890123456789012345678901234567890
    
    lazy found at position 36
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

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