Len

Syntax:

    output= Len( string )

Command Availability:

Available on all microcontrollers.

Explanation:

The Len function returns a byte value that is the length of a phrase or sentence, including spaces. The format is:

    target_byte_variable = Len("Phrase")

Another example: this code loops through the For-Next loop 12 times, as determined by the length of the string.

    ' create a test string of 12 characters
    dim teststring as string * 12

    teststring = "0123456789AB"
    for loopthrustring = 1 to len(teststring)          ' <<< the Len instruction
       hserprint mid(teststring, loopthrustring , 1)
    next

Key line: len(teststring) — returns 12, the number of characters in teststring, so the loop runs exactly once per character regardless of how the string’s declared size changes.

See Also:

  • Mid — extracting characters using a position derived from Len
  • Asc — related command in the same category