c++中 strchr strrchr wcsrchr _tcsrchr 字串操作
阿新 • • 發佈:2019-01-03
strchr strrchr wcsrchr _tcsrchr 字串操作
1)
char *strchr( const char *string, int c );
wchar_t *wcschr( const wchar_t *string, wchar_t c );
Find a character in a string. 查詢一個字串中首次出現的指定字元。
Return Value:Each of these functions returns a pointer to the first occurrence of c in string(address)
(2)
char *strrchr( const char *string, int c);
char *wcsrchr( const wchar_t *string, int c );
Scan a string for the last occurrence of a character.:查詢一個字串中最後出現的指定字元。
Return Value:Each of these functions returns a pointer to the last occurrence of c in string(address)
找出字串中最後一個出現查詢字元的地址,然後將該字元出現的地址返回。
附上原始碼:
- wchar_t * _DEFUN (wcsrchr, (s, c), _CONST wchar_t * s _AND wchar_t c)
- {
- _CONST wchar_t *p;
- p = s;
- while (*p)
- p++;
- while (s <= p)
- {
- if (*p == c)
- {
-
/** LINTED interface specification */
- return (wchar_t *) p;
- }
- p--;
- }
- return NULL;