Instance
The number of characters that the output looks for before the character "W" is found in the string "Hello world!":
<?phpecho strcspn ("Hello world!", "w");? >
Definition and usage
The STRCSPN () function returns the number of characters (including spaces) that are searched for in a string before any specified characters are found.
Tip: Use the strspn () function to the number of characters found in the string that contains only characters from a specifi Ed character List.
Note: This function is Binary-safe.
Grammar
STRCSPN (String,char,start,length)
parameters |
description |
string |
required. Specifies the string to search for. |
char |
start |
optional. Specifies where to start the search. |
length |
optional. Specifies the length of the string (how many characters to search). |
More examples
Example 1
Use all the parameters to output the number of characters found before the character "W" in the string "Hello world!":
<?phpecho strcspn ("Hello world!", "W", 0,6); The start position is 0 and the length of the search string is 6.? >
function function: Compare the characters in string str2 with a word typeface in Str (that is, whether the characters in the str2 are present in str1), and then stop and return the index value of this matching character in str1 if the first occurrence of the str1 is the same as the reference. Failure returns the length of the str1.
Return Description: Returns the index value of this match-equal character in str1, which is an integer value.
Other instructions: not currently.
Instance:
#include <string.h> #include <stdio.h>int main () { char *str1= "aaaaakkkeeee"; Char *str2= "john,he like writing!"; int inttemp; INTTEMP=STRCSPN (STR1,STR2); Nonspacing each word in str2 to match in Str1, if the character appears in str1, returns the index value of this character in str1 printf ("The first index of the character both in str1 and STR2:%d ", inttemp); return 0;}
In VC + + 6.0 compile run: