substr

The substr() function extracts a substring from the specified string variable (string1) based on the provided starting position (start) and optional length (length). The first character in string1 is position 1. If the optional length is not specified, then substr() returns all characters from the starting position through the end of the string.

An error is generated if a negative starting position is given or if the starting position is past the end of the string (for example, if string1 is 10 characters long and the specified starting location is 12).

The substr() function supports single-byte an multiple-byte character strings. In either case, the starting position and length are in units of characters, not bytes.

result = substr (string1, start [, length]);

string1

Required. The string from which a substring is extracted.
start Required. Specifies the substring starting position within string1. The first character in string1 is position 1.
length Optional. Specifies the maximum length of the substring.

result contains the new substring.

UserList = "User1, User2, User3";
result1 = substr (UserList, 8, 5);
result2 = substr (UserList, 8);

In this example, result1 contains the value User2, and result2 contains User2, User3.

UserList = "書策搜書策搜書策搜書策搜書策搜書策搜書策搜";
result = substr (UserList, 8, 5);

In this example, result contains the value 策搜書策搜.