Translations of this page?:

strstr

语法:

    #include <cstring>
    const char *strstr( const char *str1, const char *str2 );
          char *strstr(       char *str1, const char *str2 );

strstr返回str1中第一次出现str2的指针,如果没有匹配返回NULL。如果str2的长度为零,则strstr简单的返回str1.

例如,下面的代码检查一个字符串是否出现在另一个中:

    char* str1 = "this is a string of characters";
    char* str2 = "a string";
    char* result = strstr( str1, str2 );
    if( result == NULL ) printf( "Could not find '%s' in '%s'\n", str2, str1 );
    else printf( "Found a substring: '%s'\n", result );

运行后,上面的代码显示这个输出:

    Found a substring: 'a string of characters'

相关主题: memchr, strchr, strcspn, strpbrk, strrchr, strspn, strtok

 
• • • SitemapRecent changesRSScc