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

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 be searched

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. The return value is zero-based. The first character is zero, the second is 1, and so on.

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() (see 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 climb a mountain.";
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 climb a mountain.
strpbrk returns a string: way to climb a mountain.
strcspn returns an integer: 22

See Also

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

Siebel eScript Language Reference Copyright © 2007, Oracle. All rights reserved.