標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
Language Environment |
両方 |
#include <string.h>
size_t strspn(const char *string1, const char *string2);
string2 で示されるストリングに含まれる文字全体で構成 される、string1 で示されるストリングの最初の最大部分の 長さを計算します。
strspn() は、検出されたサブストリングの長さを戻します。
⁄* CELEBS50
This example finds the first occurrence in the array string
of a character that is neither an a, b, nor c. Because the
string in this example is cabbage, &strspn. returns 5, the
length of the segment of cabbage before a character that is
not an a, b or c.
*⁄
#include <stdio.h>
#include <string.h>
int main(void)
{
char * string = "cabbage";
char * source = "abc";
int index;
index = strspn( string, "abc" );
printf( "The first %d characters of ¥"%s¥" are found in ¥"%s¥"¥n",
index, string, source );
}
The first 5 characters of "cabbage" are found in "abc"