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

Clib.strcspn() Method


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

Syntax

Clib.strcspn(string, charSet)

Parameter
Description
string
A literal string, or a variable containing a string, to be searched
charSet
A literal string, or a variable containing a string, which contains the set of characters to search for

Returns

If no matching characters are found, the length of the string; otherwise, the offset of the first matching character from the beginning of string.

Usage

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).

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

This code results in the following output:

See Also

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


 Siebel eScript Language Reference 
 Published: 18 April 2003