Positron Compiler Documentation

Len

Source: Positron8 Compiler User Manual, PDF page 361

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, Long, 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. A third possibility for Source String is a label name, in which case a null terminated Quoted String of Characters is read from a Flash memory table. Assignment Variable is a user defined variable of type Bit, Byte, Word, Long, Dword, Float or Array.

Example 1

' Display the length of SourceString
  Device = 18F25K20
                                       ' A suitable device for Strings
  Declare Xtal = 16
                                ' Tell the compiler the device is operating at 16MHz
  Declare Hserial_Baud = 9600
  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
  HRsoutLn Dec Length
                                       ' Display the result, which will be 11

Example 2

' Display the length of a Quoted Character String
  Device = 18F25K20
                                       ' A suitable device for Strings
  Declare Xtal = 16
                                ' Tell the compiler the device is operating at 16MHz
  Dim Length as Byte
  Length = Len("Hello World")
                                       ' Find the length
  HRsoutLn Dec Length
                                       ' Display the result, which will be 11

Example 3

' Display the length of SourceString using a pointer to SourceString
  Device = 18F26K40
                                       ' A suitable device for Strings
  Declare Xtal = 16
                                ' Tell the compiler the device is operating at 16MHz
  Declare Hserial_Baud = 9600
  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
  HRsoutLn Dec Length
                                       ' Display the result, which will be 11

Example 4

' Display the length of a Flash memory string
  Device = 18F26K40
                                ' A suitable device for Strings
  Declare Xtal = 16
                                ' Tell the compiler the device is operating at 16MHz
  Declare Hserial_Baud = 9600
  Dim Length as Byte
'
' Create a null terminated string of characters in flash memory
'
  Dim Source As Flash = "Hello World", 0
  Length = Len(Source)
                             ' Find the length
  HRsoutLn Dec Length
                             ' Display the result, which will be 11

See also : Creating and using Strings, Creating and using Virtual Strings with

Cdata, Cdata, Left$, Mid$, Right$, Str$, ToLower, ToUpper, AddressOf.