BASIC Language Reference Manual > Command and Function Reference >

LEFT$ Function


Returns a string consisting of a certain number of characters from the beginning (left-hand side) of a given string.


LEFT$(string expression, number of characters)

Remarks and Examples

The LEFT$ function takes two parameters: a string to examine (we will call this string X$), and the number of characters to extract from the string X$ (we will call this number n).

LEFT$ returns a string consisting of the leftmost n characters of the string X$, as shown in the following example:

10 A$ = "Baseball"
20 PRINT LEFT$(A$, 4)

If n is greater than the length of the string X$, then the entire string X$ is returned:

PRINT LEFT$("Test", 10)

If n is zero, an empty string is returned:

PRINT "(" & LEFT$("Test", 0) & ")"

A negative value for n will cause an error at runtime.

See also: MID$, RIGHT$

Copyright 2006-2008, Kevin Matz, All Rights Reserved.