STR_CUT, MID, SUBSTR

Script Functions: It copies characters of a string.

Syntax

STR_CUT (String, Start[, Length])
MID (String, Start[, Length])
SUBSTR (String, Start[, Length])

Syntax

Description/Format

String

An alphanumeric string.
Format: script literal or script variable

Start

The start position for the part that should be copied.
Format: number without quotation marks or script variable

Length

The number of characters that should be copied.
Format: number without quotation marks or script variable


Return code

A part of a string.

Comments

These script functions all serve the same purpose. They copy characters from a given String. Length is an optional parameter - not specifying it means that all characters until the end of the String are returned.

Note: You can specify an absolute length that exceeds the number of characters that are available in the string. In this case, the functions return the defined characters with additional blanks that are appended. If necessary, you can truncate these blanks with the STR_RTRIM function.

The string itself remains unchanged. 

Examples

In the first example, the script function returns "CD". The result of the second example is "CDEFGH" - all characters until the end of the string are included.

:SET &STRING# = MID("ABCDEFGH",3,2)

:SET &STRING# = SUBSTR("ABCDEFGH",3)

The following example uses the script function SUBSTR to split a user-defined term. The first three characters are assigned to the first script variable and the last character to the second script variable.

:READ &TABNAME#, "04", "Please specify table name xxxy"
:
SET &TABPRE# = SUBSTR(&TABNAME#,1,3)
:
SET &TABSUF# = SUBSTR(&TABNAME#,4,1)

The following example sets a length that exceeds the number of characters that are available in the string. Therefore, the function appends blanks for the missing characters. The result is >>CDEFGH    <<.

:SET &STRING# = STR_CUT("ABCDEFGH",3,10)
:PRINT ">>&STRING#<<"

See also:

Script element Description

STR_SUBSTITUTE

It replaces characters or strings within a string.
STR_CAT It combines two strings to a new string.
STR_RTRIM Deletes the empty spaces at the end of a string.

Script Elements - Strings

About Scripts
Script Elements - Alphabetical Listing

Script Elements - Ordered by function