strspn() - ストリングの検索

標準

標準/拡張機能 C/C++ 依存項目

Language Environment
ISO C
XPG4
XPG4.2
C99
Single UNIX Specification、バージョン 3

両方  

形式

#include <string.h>

size_t strspn(const char *string1, const char *string2);

機能説明

string2 で示されるストリングに含まれる文字全体で構成 される、string1 で示されるストリングの最初の最大部分の 長さを計算します。

戻り値

strspn() は、検出されたサブストリングの長さを戻します。

CELEBS50
⁄* 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"

関連情報