Mid (Function)
Returns a substring of a string
Syntax
`
Declare Function Mid ( ByRef str as Const String, ByVal start as integer ) as String
Declare Function Mid ( ByVal str as Const WString Ptr, ByVal start as integer ) as WString
Declare Function Mid ( ByRef str as Const String, ByVal start as integer, ByVal n as integer ) as String
Declare Function Mid ( ByVal str as Const WString Ptr, ByVal start as integer, ByVal n as integer ) as WString
`
Usage
`
result = Mid[$]( str, start [, n ] )
`
Parameters
`str`
The source string.
`start`
The start position in `str` of the substring.
`n`
The substring length, in characters.
Description
Returns a substring starting from `start` in `str`. If `str` is empty then the null string (`"``"`) is returned. If `start <= 0` then the null string (`"``"`) is returned.
In the first form of `Mid`, all of the remaining characters are returned. In the second form, if `n < 0` or `n >= len(str)` then all of the remaining characters are returned.
Example
`
Print Mid("abcdefg", 3, 2)
Print Mid("abcdefg", 3)
Print Mid("abcdefg", 2, 1)
`
will produce the output:

    cd
    cdefg
    b

A Unicode example:
Wiki: code rendered this way to allow display of the Unicode characters.

dim text as wstring * 20 text = "Привет, мир!" print mid(text, 6, 4) ' displays "т, м"

Platform Differences

- DOS does not support the wide-character string versions of `Mid`.

Dialect Differences

- The string type suffix "`$`" is obligatory in the -lang qb dialect.
- The string type suffix "`$`" is optional in the -lang fblite and -lang fb dialects.

Differences from QB

- QB does not support Unicode.

See also

- `InStr`
- `Mid (Statement)`
- `Left`
- `Right`
- `Asc`