Method

Mid


Description

Returns a portion of a string. The first character is numbered 1.

Usage

result=Mid(source, start [,length])

OR

result=stringVariable.Mid(start [,length])

Part

Type

Description

result

String

The portion of source from start and continuing for length characters or all remaining characters if length is not specified.

source

String

Required. The string from which characters are returned.

start

Integer

Required. The position of the first character to be returned.

length

Integer

Optional. The number of characters to return from source.

stringVariable

String

Any variable of type String.

Notes

To determine the number of characters in a string, use the Len function.

The Mid function works properly with international text.

Sample code

These examples use the Mid function to return portions of a string.

Var s As String
s = Mid("This is a test", 6) // returns "is a test"
s = Mid("This is a test", 11, 4) // returns "test"

s = "This is a test"
s = s.Mid(11, 4) // returns "test"

This example converts the text string in TextField1 to hex and writes the result to TextField2:

TextField2.Text = ""
For i As Integer = 1 To TextField1.Text.Length
  TextField2.Text = TextField2.Text + "&h" + Hex(Asc(Mid(TextField1.Text, i, 1)))
Next

Compatibility

All project types on all supported operating systems.

See also

Asc, Chr, String.IndexOf, Left, Len, Right functions.