Mid$() function - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Returns a string extracted from the middle of another string. You can call this function from the MapBasic window in MapInfo Pro.

Syntax

Mid$( string_expr, position, length )

string_expr is a string expression.

position is a numeric expression, indicating a starting position in the string.

length is a numeric expression, indicating the number of characters to extract.

Return Value

String

Description

The Mid$() function returns a substring copied from the specified string_expr string.

Mid$() copies length characters from the string_expr string, starting at the character position indicated by position. A position value less than or equal to one tells MapBasic to copy from the very beginning of the string_expr string.

If the string_expr string is not long enough, there may not be length characters to copy; thus, depending on all of the parameters, the Mid$() may or may not return a string length characters long. If the position parameter represents a number larger than the number of characters in string_expr, Mid$() returns a null string. If the length parameter is zero, Mid$() returns a null string. If the length or position parameters are fractional, MapBasic rounds to the nearest integer.

Example

Dim str_var, substr_var As String
str_var = "New York City"
substr_var = Mid$(str_var, 10, 4)

' substr_var now contains the string "City" 

See Also:

InStr() function, Left$() function, Right$() function