OScript API/Built-in Package Index |
A String is any sequence of zero or more characters. String values can be obtained by:
String literals consist of a sequence of zero or more characters delimited by either single or double quotation marks. For example:
String myName = "Arnold Wilson" String myBDay = 'August 20th, 1934'
Single or double quotation marks can be embedded in the String by alternating the delimiters used or by doubling the desired quotation character. For example:
String phrase1 = 'The proper term is "regardless."' String phrase2 = "She can''t understand." String phrase3 = "His name is John ""Rusty"" Smith"
Note that there are two single quotation characters between the n and the t in the String phrase2.
Strings can be concatenated using the + operator. For example:
String myString = 'This is a test.' Echo( myString + ' Really.' ) //displays 'This is a test. Really.'
Substrings can be deleted from a String using the - operator. When using the - operator to delete substrings, only the first occurrence of the substring (read from left to right) is removed from the String. If the substring is not found, an Error does not occur. For example:
String myString = "This is a test." Echo( myString - "is" ) //displays "Th is a test." Echo( myString - "is" - "is" ) //displays "Th a test."
The characters in a String can be referenced using the index operator ( [ ] ), where the first character in the String is character 1. For example, the sixth and seventh characters of the String variable myString can be referenced using the following syntax:
String myString = "this is a test." myString[ 1 ] = Str.Upper( myString[ 1 ] ) Echo( myString ) //displays "This is a test." myString[ 6 : 7 ] = "is not" Echo( myString ) //displays "This is not a test."
You can use an open-ended range, for example, [ : 6 ] specifies a range from the beginning through the 6th character of the String, and [ 3: ] specifies a range from the third through the last character of the String.
You can also refer to String characters using negative numbers, where the last character of the String is -1. For example, myString[ -2:-1 ] returns a String containing the last two characters of myString.
For more information about the operators used with Strings, see the Arithmetic section and the Indexing section within the Operators section of the OScript Language Reference Manual.
Copyright © 2021 OpenText Corporation. All rights reserved. |