Abstract
This is a common function in practice. Unfortunately, it is a string in C. h does not provide this function. In this article, a small function is implemented to this function and matched with pointer.
Introduction
How can I capture a specified character from a string? (C/C ++) (c), which can already contain 99% of requirements. The only defect is that string. most of the letters in H are returned to the char * of the callback. If you want to upgrade the function, use the string. h. For the original function, the vertex must provide the pointer function.
Both the third and fourth regions use char *‧
Strchrp. C/C
1 /*
2 (C) oomusou 2009 Http://oomusou.cnblogs.com
3
4 Filename: strchrp. c
5 Compiler: Visual C + + 9.0
6 Description: Demo how to get string from specify Char to Char (pointer ver .)
7 Release: 04/26/2009 1.0
8 */
9
10 # Include < Stdio. h >
11 # Include < String . H >
12
13 Void Strchrp ( Char * DeST, Char * SRC, Char * Begin, Char * End ){
14 Int Len = Strlen (BEGIN) - Strlen (end );
15 Strncpy (DEST, begin, Len );
16 Dest [Len] = ' \ 0 ' ;
17 }
18
19 Int Main (){
20 Char SRC [] = " [10, 20] " ;
21 Char Dest [ 20 ];
22
23 Strchrp (DEST, SRC, strchr (SRC, ' , ' ) + 1 , Strchr (SRC, ' ] ' ));
24
25 Printf ( " % S " , DEST );
26 }
Results
20
Known Issue
In this version, when begin and end are null, the attacker will be generated and a better anti-stay mechanism is required ‧
Download the complete program
Strchrp.7z