windowsc++⽐较字符串不区分⼤⼩写//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]
Generic-Text Routine Mappings
TCHAR.H routine_UNICODE & _MBCS not defined
_tcsstr strstr_mbsstr n/a n/a_mbsstr_l
// 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;
字符串函数putspch = 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
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论