contents   index   previous   next



Clib.strcspn()

syntax:

Clib.strcspn(str, chrSet)

where:

str - string to be searched.

 

chrSet - set of characters to search for.

 

return:

number - offset into str to a found character on success, else the length of str.

 

description:

This method searches the parameter string for any of the characters in the string chrSet and returns the offset of that character. If no matching characters are found, it returns the length of the string. This method is similar to Clib.strpbrk(), except that Clib.strcspn() returns the offset number, or index, for the first character found, while Clib.strpbrk.() returns the string beginning at that character.

 

see:

Clib.strpbrk()

 

example:

// The following fragment demonstrates

// the difference between Clib.strcspn() and

// Clib.strpbrk().

 

var string =

    "There's more than one way to skin a cat.";

var rStrpbrk = Clib.strpbrk(string, "dxb8w9k!"); 

var rStrcspn = Clib.strcspn(string, "dxb8w9k!"); 

Clib.printf("The string is: %s\n", string); 

Clib.printf("\nstrpbrk returns a string: %s\n",

            rStrpbrk); 

Clib.printf("\nstrcspn returns an integer: %d\n",

            rStrcspn);

Clib.printf("string +strcspn = %s\n", string +

            rStrcspn); Clib.getch(); 

 

// And results in the following output:

//  The string is:

//  There's more than one way to skin a cat. 

//  strpbrk returns a string: way to skin a cat. 

//  strcspn returns an integer: 22

//  string +strcspn = way to skin a cat

 


Clib.stricmp()