//z 2014-04-18 17:41:49 BG57IV3@XCL T745044962 .K.F253293061 [T244,L3296,R157,V4779] 使用函数 StrStrI 比较字符串,不区分大小写。 StrStrI function Finds the first occurrence of a substring within a string. The comparison is not case-sensitive. Return value 包含头文件 Shlwapi.h 库 Shlwapi.lib 注意:与 wcstr 不同,在传入一个空字符串时,会返回 NULL 。 Type: PTSTR Returns the address of the first occurrence of the matching substring if successful, or NULL otherwise. Header Shlwapi.h Library Shlwapi.lib nlike strstr() and wcsstr() passing an emtpy string results in NULL being returned. pszFound = StrStrI(L"abcdefg", L""); // returns NULL pszFoundStrStr = wcsstr(L"abcdefg", L""); // returns L"abcdefg" char *strstr( const char *str, const char *strSearch ); // C only char *strstr( char *str, const char *strSearch ); // C++ only const char *strstr( const char *str, const char *strSearch ); // C++ only wchar_t *wcsstr( const wchar_t *str, const wchar_t *strSearch ); // C only wchar_t *wcsstr( wchar_t *str, const wchar_t *strSearch ); // C++ only const wchar_t *wcsstr( const wchar_t *str, const wchar_t *strSearch ); // C++ only unsigned char *_mbsstr( const unsigned char *str, const unsigned char *strSearch ); // C only unsigned char *_mbsstr( unsigned char *str, const unsigned char *strSearch ); // C++ only const unsigned char *_mbsstr( const unsigned char *str, const unsigned char *strSearch ); // C++ only unsigned char *_mbsstr_l( const unsigned char *str, const unsigned char *strSearch, _locale_t locale ); // C only unsigned char *_mbsstr_l( unsigned char *str, const unsigned char *strSearch, _locale_t locale ); // C++ only const unsigned char *_mbsstr_l( const unsigned char *str, const unsigned char *strSearch, _locale_t locale ); // C++ only //z 2014-04-18 17:41:49 BG57IV3@XCL T745044962 .K.F253293061 [T244,L3296,R157,V4779]
TCHAR.H routine
_UNICODE & _MBCS not defined
_MBCS defined
_UNICODE defined
_tcsstr
strstr
_mbsstr
wcsstr
n/a
n/a
_mbsstr_l
n/a
// crt_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"; int main( void ) { char *pdest; int result; printf( "String to be searched:\n %s\n", string ); printf( " %s\n %s\n\n", fmt1, fmt2 ); pdest = strstr( string, str ); result = (int)(pdest - string + 1); if ( pdest != NULL ) printf( "%s found at position %d\n", str, result ); else printf( "%s not found\n", str ); }/* strstr example */ #include <stdio.h> #include <string.h> int main () { char str[] ="This is a simple string"; char * pch; pch = strstr (str,"simple"); strncpy (pch,"sample",6); puts (str); return 0; }String to be searched: The quick brown dog jumps over the lazy fox 1 2 3 4 5 12345678901234567890123456789012345678901234567890 lazy found at position 36