Function SubString(str, from, to)

SubString

The function SubString retrieves a substring from a specific string, based on the start and end position of this substring within this string.

SubString(
     str,      ! (input) a scalar string expression
     from,     ! (input) an integer value
     to        ! (input) an integer value
     )

Arguments

str

The string from which you want to retrieve the substring.

from

The start position of the substring within str.

to

The end position of the substring within str.

Return Value

The function returns the requested substring.

Example

The code:

sp_str := "hello HELLO";
sp_res := subString( sp_str, 4, 5 );
display sp_res ; ! sp_res := "lo" ;

Note

If the arguments from and to are positive, then the position is calculated from the start of the string (i.e. the first character is on position \(1\)). If the arguments from and to are negative, then the position is calculated from the end of the string (i.e. the last character is on position \(-1\)). from must be less than or equal to to, and if either of the values exceeds the length of the string, they are automatically set within the proper range.