![]() Chapter Contents |
![]() Previous |
![]() Next |
| stcpma |
| Portability: | SAS/C extension |
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| EXAMPLE | |
| RELATED FUNCTIONS | |
| SEE ALSO |
| SYNOPSIS |
#include <lcstring.h> int stcpma(char *str, const char *pat);
| DESCRIPTION |
stcpma
tests the input string addressed by
str
to determine whether it starts with a substring matching the pattern that
pat
points to. The search terminates if a match
is not found at the beginning of the input string.
The pattern format can be specified using the symbols
+
,
*
, and
?
, as described in the discussion of
stcpm
stcpm
.
Although the
stcpm
and
stcpma
functions use the same pattern-matching
notation,
stcpma
is different from
stcpm
in two ways:
stcpma
looks
for a match to the search pattern (
pat
)
only at the beginning of the input string (
str
). The
stcpm
function scans the
entire string for the first match, which may or may not occur at the beginning.
stcpma
does
not take a third argument.
| RETURN VALUE |
If it is successful,
stcpma
returns the length of the character sequence that matches the
search pattern, or it returns 0 if no match is found.
In comparison to
stcpm
,
both
stcpm
and
stcpma
can find the search pattern
William
A*.* *Tell
in the following input string:
"William A. Tell, Margaret Fairfax-Tell"
However,
stcpma
cannot
find the search pattern in this string:
"Margaret Fairfax-Tell, William A. Tell"
And
stcpma
cannot
find it in this string, which contains an initial blank:
" William A. Tell"
| EXAMPLE |
#include <lcstring.h>
#include <stdio.h>
main()
{
static char *sps[ ] = {
"William Tellas Sr.", /* no middle initial */
"William A Tella ", /* middle initial */
"William AAA. Tell!! ---", /* initial and period */
"William S. Teller; Then..", /* wrong initial */
};
int length, i;
/* Find William Tell, whether or not he used his */
/* middle initial. */
for (i = 0; i < 4; i++) {
if (length = stcpma(sps[i], "William A*.* *Tell"))
printf("%d. Match result = %.*s\n", i,length, sps[i]);
else
printf("%d. No match for string = %s\n",i,sps[i]);
}
}
| RELATED FUNCTIONS |
| SEE ALSO |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.