Len
Source: Positron16 Compiler User Manual, PDF page 363
Syntax
Assignment Variable = Len(Source String)
Overview
Find the length of a String. (not including the null terminator) .
Parameters
Source String can be a String variable, or a Quoted String of Characters. The Source String can also be a Byte, Word, 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. 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. Assignment Variable is a user defined variable.
Example 1
' Display the length of 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 Length as Byte
SourceString = "Hello World"
' Load the source string with characters
Length = Len(SourceString)
' Find the length of the String
Print Dec Length
' Display the result, which will be 11
Example 2
' Display the length of a Quoted Character String
Device = 24HJ128GP502
' Select the device to compile for
Declare Xtal = 16
Dim Length as Byte
Length = Len("Hello World")
' Find the length of the String
Print Dec Length
' Display the result, which will be 11
Example 3
' Display the length of SourceString 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 Length as Byte
' Display the length of SourceString
Dim SourceString as String * 20 ' Create a String capable of 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)
Length = Len(StringAddr)
' Find the length of the String
Print Dec Length ' Display the result, which will be 11
Example 4
' Display the length of a code memory string
Device = 24HJ128GP502
' Select the device to compile for
Declare Xtal = 16
Dim Length as Byte
'
' Create a null terminated string of characters in code memory
'
Dim Source as Code = "Hello World", 0
Length = Len(Source)
' Find the length of the String
Print Dec Length
' Display the result, which will be 11