Bookshelf Home | Contents | Index | PDF |
Siebel eScript Language Reference > Siebel eScript Commands > The String Object > String Object Methods and Properties in Siebel eScriptThe following conventions are used in the methods and properties in this topic:
String charAt() MethodThis method returns a character at a certain place in a string. Syntax
ReturnsA string of length 1 representing the character at position. UsageTo get the first character in a string, use index 0, as follows: var string1 = "a string"; To get the last character in a string, use: var lastchar = string1.charAt(string1.length - 1); If position does not fall between 0 and See AlsoString indexOf() Method String.fromCharCode() Static MethodThis method returns a string created from the character codes that are passed to it as parameters. SyntaxString.fromCharCode(code1, code2, ... coden) ReturnsA new string containing the characters specified by the codes. UsageThis static method allows you to create a string by specifying the individual Unicode values of the characters in it. The identifier String is used with this static method, instead of a variable name as with instance methods because it is a property of the String constructor. The parameters passed to this method are assumed to be Unicode values. The following line: var string1 = String.fromCharCode(0x0041,0x0042); sets the variable string1 to ExampleThe following example uses the decimal Unicode values of the characters to create the string var seblStr = String.fromCharCode(83, 105, 101, 98, 101, 108); See AlsoString indexOf() MethodThis method returns the position of the first occurrence of a substring in a string. stringVar.indexOf(substring [, offset]) ReturnsThe position of the first occurrence of a substring in a string variable. UsagestringVar.indexOf() searches for the entire substring in a string variable. The substring parameter may be a single character. If offset is not given, searching starts at position 0. If it is given, searching starts at the specified position. var string = "what a string"; returns the position of the first var magicWord = "abracadabra"; returns 3, the index of the first NOTE: The indexOf() method is case sensitive. See AlsoString charAt() Method String lastIndexOf() MethodThis method finds the position of the last occurrence of a substring in a string. SyntaxstringVar.lastIndexOf(substring [, offset])
ReturnsIf offset is provided, the function returns the rightmost position, not greater than offset, at which substring begins in the string contained in the variable stringVar. If offset is not provided, the function returns the rightmost position in the entire string at which substring begins. If substring is not found, or if offset is outside the range of valid positions in the string, then the function returns -1. UsageThe stringVar.lastIndexOf() function is used to determine the last position within a string that a substring occurs. By setting the offset parameter, the search can be limited to a substring of leftmost characters of the string. Substring is not required to occur entirely within the substring of the string bounded by offset. Its first character is required to occur at a position no greater than offset. var string = "what a string"; returns the position of the last var magicWord = "abracadabra"; returns 7, the position of the last "abr" beginning at a position no greater than 8. See AlsoString charAt() Method String length PropertyThe length property stores an integer indicating the length of the string. SyntaxUsageThe length of a string can be obtained by using the length property. For example: var string1 = "No, thank you."; displays the number 14, the number of characters in the string. Note that the index of the last character in the string is equivalent to ExampleThis code fragment returns the length of a name entered by the user (including spaces). var userName = "Christopher J. Smith"; String match() MethodThis method returns an array of strings that are matches within the string against a target regular expression. SyntaxReturnsThis method returns an array with various elements (the matched strings that are found), and their property sets. The elements returned depend on the attributes of the regular expression. The method returns null if no match is found. UsageWhen match() is executed with the global attribute, "g", not set on the regular expression, then the return array and its properties are equivalent to those returned under the same circumstances using the RegExp exec() method. If a match is found, then:
These elements and their numbers correspond to groups in regular expression patterns and replacement expressions. The returned array includes the following properties:
The return values, and the index and input properties are the same as those of the returned array from the RegExp exec() method when exec() is used with a regular expression whose global attribute is not set. When match() is executed with the global attribute, "g", set on the regular expression, and a match is found, then:
ExamplesThe following example calls match() against a regular expression whose global attribute is not set. The output is commented. function fn () return[0] = etter \\First text containing primary pattern ...er (any three \\characters followed by "er") The following example calls match() against a regular expression whose global attribute is set. The method returns matches of the regular expression's primary pattern that do not overlap. function fn () match [0] = ttt The output does not include the "ttt" instance that starts at position 1 or "t t" because these instances start within other strings that are returned. See alsoString split() MethodThis method splits a string into an array of strings based on the delimiters in the parameter substring. SyntaxReturnsAn array of strings, creating by splitting stringVar into substrings, each of which begins at an instance of the delimiter character. UsageThis method splits a string into an array of substrings such that each substring begins at an instance of delimiter. The delimiter is not included in any of the strings. If delimiter is omitted or is an empty string ( This method is the inverse of arrayVar.join(). ExampleThe following example splits a typical Siebel command line into its elements by creating a separate array element at each space character. The string has to be modified with escape characters to be comprehensible to Siebel eScript. Also, the cmdLine variable must appear on a single line, which space does not permit in this volume. function Button3_Click () Running this code produces the following result. The following items appear in the array: See AlsoString replace() MethodThis method searches a string using the regular expression pattern defined by pattern. If a match is found, it is replaced by the substring defined by replexp. SyntaxstringVar.replace(pattern, replexp)
ReturnsThe original string with replacements according to pattern and replexp. UsageThe string is searched using the regular expression pattern defined by pattern. If a match is found, it is replaced by the substring defined by replexp. The parameter replexp may be:
If you are using the T eScript engine and any replacements are made, appropriate RegExp object static properties such as RegExp.leftContext, RegExp.rightContext, and RegExp.$n are set. These properties provide more information about the replacements. NOTE: The ST eScript engine does not support the following static properties of the RegExp object: RegExp.$n (including '$_' and '$&'), RegExp.input, RegExp.lastMatch, RegExp.lastParen, RegExp.leftContext, RegExp.rightContext. The following table shows the special characters that may occur in a replacement expression. Examplevar rtn; // rtn == "one zzz three zzz one" // rtn == "one twozzz three twozzz one"; // rtn == "one 5 three 5 one" // rtn == "one twotwo three twotwo one"; substring() MethodThis method retrieves a section of a string. SyntaxstringVar.substring(start[, end])
ReturnsA new string, of length end - start, containing the characters that appeared in the positions from start to end - 1 of stringVar. UsageThis method returns a portion of stringVar, comprising the characters in stringVar at the positions start through end - 1. The character at the end position is not included in the returned string. If the end parameter is not used, stringVar.substring() returns the characters from start to the end of stringVar. ExampleFor an example, see String indexOf() Method. See AlsoString charAt() Method toLowerCase() MethodThis method returns a copy of a string with the letters changed to lowercase. SyntaxReturnsA copy of stringVar in lowercase characters. UsageThis method returns a copy of stringVar with uppercase letters replaced by their lowercase equivalents. ExampleThe following code fragment assigns the value var poet = "E. E. Cummings"; See AlsotoUpperCase() MethodThis method returns a copy of a string with the letters changed to uppercase. SyntaxReturnsA copy of stringVar in uppercase characters. UsageThis method returns a copy of stringVar, with lowercase letters replaced by their uppercase equivalents. ExampleThe following fragment accepts a filename as input and displays it in uppercase: var filename = "c:\\temp\\trace.txt";; See Also |
Siebel eScript Language Reference |