Siebel eScript Language Reference > Siebel eScript Commands > The Clib Object String Methods >

Clib.strcspn() Method

This method searches a string for any of a group of specified characters.


Clib.strcspn(string, charSet)



A literal string, or a variable containing a string, to be searched


A literal string, or a variable containing a string, which contains the set of characters to search for


If no matching characters are found, the length of the string; otherwise, the offset of the first matching character from the beginning of string. The return value is zero-based. The first character is zero, the second is 1, and so on.


This method searches the parameter string for any of the characters in the string charSet, and returns the offset of that character. This method is similar to Clib.strpbrk(), except that Clib.strpbrk() returns the string beginning at the first character found, while Clib.strcspn() returns the offset number for that character.

When possible, you should use the standard JavaScript method substring() (read string.replace() Method).


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!");
TheApplication().RaiseErrorText("The string is: " + string +
   "\nstrpbrk returns a string: " + rStrpbrk +
   "\nstrcspn returns an integer: " + rStrcspn);

This code 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

See Also

Clib.strchr() Method
Clib.strpbrk() Method
string.replace() Method

Siebel eScript Language Reference