Len() 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 the number of characters in a string, or the number of bytes in a non-string variable. You can call this function from the MapBasic window in MapInfo Pro.
Note: For a string variable, the Len() function returns only the number of characters in the string, not the number of bytes. You can use the StringByteLength() function to get the number of bytes in the string.

For example, Len("ABCD属性コ構") returns 8 as the number of characters in the string, but StringByteLength("ABCD属性コ構", WindowsJapanese) returns 12 as the number of bytes for the string in WindowsJapanese charset.

Syntax

Len( expr ) 

expr is a variable expression. expr cannot be a Pen, Brush, Symbol, Font, or Alias.

Return Value

SmallInt

Description

The behavior of the Len() function depends on the data type of the expr parameter.

If the expr expression represents a character string, the Len() function returns the number of characters in the string.

Otherwise, if expr is a MapBasic variable, Len() returns the size of the variable, in bytes. Thus, if you pass an integer variable, Len() will return the value 4 (because each integer variable occupies 4 bytes), while if you pass a SmallInt variable, Len() will return the value 2 (because each SmallInt variable occupies 2 bytes).

Example

Dim name_length As SmallInt
name_length = Len("Boswell")

name_length now has the value 7.

See Also: