Left$
Syntax
Destination String = Left$ (Source String, Amount of characters)
Overview
Extract n amount of characters from the left of a source string and copy them into a destination string.
Parameters
Destination String can only be a String variable, and should be large enough to hold the correct amount of characters extracted from the Source String. Source String can be a String variable, or a Quoted String of Characters. See below for more variable types that can be used for Source String. Amount of characters can be any valid variable type, expression or constant value, that signifies the amount of characters to extract from the left of the Source String. Values start at 1 for the leftmost part of the string and should not exceed 255 which is the maximum allowable length of a String variable.
Example 1.
' Copy 5 characters from the left of SourceString into DestString
'
Device = 24HJ128GP502 ' Select the device to compile for
Declare Xtal = 16
Dim SourceString as String * 20 ' Create a String capable of 20 characters
Dim DestString as String * 20 ' Create another String for 20 characters
SourceString = "Hello World" ' Load the source string with characters
'
' Copy 5 characters from the source string into the destination string
'
DestString = Left$(SourceString, 5)
Print DestString ' Display the result, which will be "Hello"
Example 2.
' Copy 5 chars from the left of a Quoted Character String into DestString
'
Device = 24HJ128GP502 ' Select the device to compile for
Declare Xtal = 16
Dim DestString as String * 20 ' Create a String capable of 20 characters
'
' Copy 5 characters from the quoted string into the destination string
'
DestString = Left$("Hello World", 5)
Print DestString ' Display the result, which will be "Hello"
The Source String can also be a Byte, Word, Dword, Float or Array variable, in which case the value contained within the variable is used as a pointer to the start of the Source String's address in RAM.
Example 3.
' Copy 5 characters from the left of SourceString into DestString using a
' pointer to SourceString
'
Device = 24HJ128GP502 ' Select the device to compile for
Declare Xtal = 16
Dim SourceString as String * 20 ' Create a String capable of 20 characters
Dim DestString as String * 20 ' Create another String for 20 characters
'
' Create a Word variable to hold the address of SourceString
'
Dim StringAddr as Word
SourceString = "Hello World" ' Load the source string with characters
'
' Locate the start address of SourceString in RAM
'
StringAddr = AddressOf(SourceString)
'
' Copy 5 characters from the source string into the destination string
'
DestString = Left$(StringAddr, 5)
Print DestString ' Display the result, which will be "Hello"
A third possibility for Source String is a label name, in which case a null terminated Quoted String of Characters is read from code memory.
Example 4.
' Copy 5 characters from the left of a code memory table into DestString
'
Device = 24HJ128GP502 ' Select the device to compile for
Declare Xtal = 16
Dim DestString as String * 20 ' Create a String capable of 20 characters
'
' Create a null terminated string of characters in code memory
'
Dim Source as Code = "Hello World", 0
'
' Copy 5 characters from label Source into the destination string
'
DestString = Left$(Source, 5)
Print DestString ' Display the result, which will be "Hello"
See also : Creating and using Strings, Creating and using code memory strings,

