Latest web development tutorials

C library functions - strspn ()

C standard library - <string.h> C standard library - <string.h>

description

Character C library functionsize_t strspn (const char * str1, const char * str2) retrieves the first string str1stringstr2not appear in the subscript.

statement

Here is strspn () function's declaration.

size_t strspn(const char *str1, const char *str2)

parameter

  • str1 - C strings to be retrieved.
  • str2 - the string contains a list of characters to be matched in the str1.

return value

This function returns str1 the first character string str2 not appear in the subscript.

Examples

The following example demonstrates strspn () function is used.

#include <stdio.h>
#include <string.h>

int main ()
{
   int len;
   const char str1[] = "ABCDEFG019874";
   const char str2[] = "ABCD";

   len = strspn(str1, str2);

   printf("初始段匹配长度 %d\n", len );
   
   return(0);
}

Let's compile and run the above program, which will result in the following:

初始段匹配长度 4

C standard library - <string.h> C standard library - <string.h>