[b][red]This message was edited by tokoG at 2006-3-30 23:34:2[/red][/b][hr]
Hi!
I came accross the new string function, strspn and checked what it does.
This site had pretty good explanation
http://www.cplusplus.com/ref/cstring/strspn.html but, all in all, I think what it does is return the number(length) of what it matches to the other string.
[b]In here, strtext & cset both contains 1 & 2 & 9, that's why the return is [red]3[/red]. Am I right?[b]
[code]
/* strspn example */
#include #include int main ()
{
int i;
char strtext[] = "129th";
char cset[] = "1234567890";
i = strspn (strtext,cset);
printf ("Length of initial number is %d
",i);
return 0;
}
Output:
Length of initial number is 3
[/code]
I don't know how this could be useful..?
Comments
:
: Hi!
:
: I came accross the new string function, strspn and checked what it does.
: This site had pretty good explanation http://www.cplusplus.com/ref/cstring/strspn.html but, all in all, I think what it does is return the number(length) of what it matches to the other string.
:
: [b]In here, strtext & cset both contains 1 & 2 & 9, that's why the return is [red]3[/red]. Am I right?[/b]
: [code]
: /* strspn example */
: #include
: #include
:
: int main ()
: {
: int i;
: char strtext[] = "129th";
: char cset[] = "1234567890";
:
: i = strspn (strtext,cset);
: printf ("Length of initial number is %d
",i);
: return 0;
: }
:
: Output:
: Length of initial number is 3
: [/code]
:
: I don't know how this could be useful..?
:
:
:
:
:
From MSDN:
[italic]Returns the index of the first character in a string that does not belong to a set of characters.
[/italic]
In your example, the letter 't' in "129th" is the first character that does not occur in the string "1234567890".
The 't' is at position 3 (zero based) in "129th", that's why the return value is 3.
Greets,
Eric Goldstein
www.gvh-maatwerk.nl
: From MSDN:
: [italic]Returns the index of the first character in a string that does not belong to a set of characters.
: [/italic]
:
: In your example, the letter 't' in "129th" is the first character that does not occur in the string "1234567890".
: The 't' is at position 3 (zero based) in "129th", that's why the return value is 3.
:
: Greets,
: Eric Goldstein
: www.gvh-maatwerk.nl
:
Cool. Very thanks you now I get it.
I tried with the following the result was [b]4[/b]
char strtext[] = "129th";
char cset[] = "12t4567890";
Because 'h' is the one that doesn't occur in the other string.