Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

1. Indicate the position within the string from which substring extraction starts. 2. Specify how many characters will be extracted.

 

Code Block
String = "Ralph Waldo Emerson"
start = 7
length = 5
substring = string[7, 5]
 
Yields the substring Waldo.

...

See also

index(), indexc()

Example

The following example shows how to use the brackets operator for substring extraction. 

Code Block
* Use for all following examples.
A = "ABCD0123456789"
 
* Extracts the substring "D0123".
temp = A[4,5]
* Extracts a null substring.
temp = A[99,4]
* Extracts the substring "9".
temp = A[-1,1]
* Extracts the substring "67".
temp = A[-4,2]
* Extracts the substring "10D".
temp = A[6,-3]
* Extracts the substring "65432".
temp = A[-4,-5]
* Extracts the substring "BCD01234".
temp = A[2,"F5"]
* Extracts the substring "CD012345".
temp = A[10,"BB"]
* The value of substring is assigned "IS A LONG".
string = "THIS IS A LONG STRING"
substring = string[6, 9]
* substring has been assigned the value "GNOL".
substring = string[14, -4]
/* FORWARD is assigned the substring "IS IS A ", which includes the blank space following the letter A. */
FORWARD = string[3,"FL"]
* BAC is assigned the substring "IS IS A LONG".
BAC = string[14,"BH"]

Unicode Extraction

...

Code Block
thisVariable = ANSI_UNICODE( "Hello World" )
hello = thisVariable[1, " ", 1]