strrchr, wcsrchr, _mbsrchr
来源:互联网 发布:源码偷取 编辑:程序博客网 时间:2024/06/05 08:14
strrchr, wcsrchr, _mbsrchr
Scan a string for the last occurrence of a character.
char *strrchr( const char *string, int c );
char *wcsrchr( const wchar_t *string, int c );
int _mbsrchr( const unsigned char *string, unsigned int c );
Routine Required Header Compatibility strrchr <string.h> ANSI, Win 95, Win NT wcsrchr <string.h> or <wchar.h> ANSI, Win 95, Win NT _mbsrchr <mbstring.h> Win 95, Win NTFor 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 versionReturn Value
Each of these functions returns a pointer to the last occurrence of c in string, or NULL if c is not found.
Parameters
string
Null-terminated string to search
c
Character to be located
Remarks
The strrchr function finds the last occurrence of c (converted to char) in string. The search includes the terminating null character.
wcsrchr and _mbsrchr are wide-character and multibyte-character versions of strrchr. The arguments and return value of wcsrchr are wide-character strings; those of _mbsrchr are multibyte-character strings. These three functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined _tcsrchr strrchr _mbsrchr wcsrchrExample
/* STRCHR.C: This program illustrates searching for a character * with strchr (search forward) or strrchr (search backward). */#include <string.h>#include <stdio.h>int ch = 'r';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/t%s/n", string ); printf( "/t/t%s/n/t/t%s/n/n", fmt1, fmt2 ); printf( "Search char:/t%c/n", ch ); /* Search forward. */ pdest = strchr( string, ch ); result = pdest - string + 1; if( pdest != NULL ) printf( "Result:/tfirst %c found at position %d/n/n", ch, result ); else printf( "Result:/t%c not found/n" ); /* Search backward. */ pdest = strrchr( string, ch ); result = pdest - string + 1; if( pdest != NULL ) printf( "Result:/tlast %c found at position %d/n/n", ch, result ); else printf( "Result:/t%c not found/n" );}
Output
String to be searched: The quick brown dog jumps over the lazy fox 1 2 3 4 5 12345678901234567890123456789012345678901234567890Search char: rResult: first r found at position 12Result: last r found at position 30
- strrchr, wcsrchr, _mbsrchr
- strchr,wcschr 及strrchr, wcsrchr,_tcschr,_tcsrchr函数
- strchr,wcschr,strstr及strrchr, wcsrchr,_tcschr,_tcsrchr函数
- c++中 strchr strrchr wcsrchr _tcsrchr 字符串操作
- wcsrchr
- 字符串中字符查找函数:strchr,wcschr 及strrchr, wcsrchr函数
- strrchr
- strrchr()
- strrchr
- strrchr
- strrchr
- strrchr
- strrchr
- strrchr
- strrchr
- strrchr
- wcsrchr的妙用
- wcsrchr的妙用
- 认识自己的不足才是进步的动力
- 程序员成功之路 ――The road ahead for programmer
- 相信百度没错!
- vc 编译 CLW C1083
- 常用数据库JDBC连接写法
- strrchr, wcsrchr, _mbsrchr
- 11月5日杂记
- SQL重复记录查询
- resin竟然开始支持PHP
- 被本地安全策略拒绝本地登录时的解决办法
- IIS和FTP
- 我的成功案例
- 在Resin环境采用PHP链接MySQL数据库
- 既时窗口的使用.doc