Previous Topic: Len - Obtain the Length of the StringNext Topic: Right - Return a Substring with Rightmost n Characters


Mid - Return a Substring from a String

Valid on NetWare, Symbian OS, UNIX, Windows and Windows CE

The Mid function returns a substring from a string.

Function format:

Mid(str as String, start as Integer, length as Integer) as String 
Mid (str as String, start as Integer) as String
str

Identifies the string from which a substring is taken.

start

Indicates the start position of the substring in str.

len

Indicates the length of the substring.

Note: The arguments start and the length must be between 1 and 65,535, inclusive. If length is omitted or if there are fewer than n length characters in str, the function returns all characters from the start position to the end of the string. If start is greater than the number of characters in str, the function returns a zero length string.

The return value of the function is a substring from the string str as described previously.

Example:

This example shows how the string operations work.

Dim text As String
Text="Unicenter TNG"

Print("Left(text,3) : " + Left(text,3))  'Uni
Print("Mid(text,4,6) : " + Mid(text,4,6)) 'center
Print("Right(text,3) : " + Right(text,3)) 'TNG
Print("Length    : " + Str(Len(text))) '13