Download OPL Language Reference Manual
Transcript
String properties Provides a reference for the properties of strings. There is a single, read-only string property. Table 26. String property Syntax Value string.length Number of characters in string. This is a read-only property. Examples: "abc".length –> 3 "".length –> 0 String methods Provides a reference for string methods. Characters in a string are indexed from left to right. The index of the first character in a string is 0, and the index of the last character is string.length-1. Table 27. String methods Syntax Effect string.substring(start [ , end ] ) Returns the substring of string starting at the index start and ending at the index end-1. If end is omitted, the tail of string is returned. Examples: "0123456".substring(0, 3) –> "012" "0123456".substring(2, 4) –> "23" "0123456".substring(2) –> "23456" string.charAt(index) Returns a one-character string containing the character at the specified index of string. If index is out of range, an empty string is returned. Examples: "abcdef".charAt(0) –> "a" "abcdef".charAt(3) –> "d" "abcdef".charAt(100) –> "" string.charCodeAt(index) Returns the ASCII code of the character at the specified index of string. Ifindex is out of range, returns NaN. Examples: "abcdef".charCodeAt(0) –> 97 "abcdef".charCodeAt(3) –> 100 "abcdef".charCodeAt(100) –> NaN 112 OPL Language Reference Manual