"Length of () (block)" redirects here. For the List block, see Length of () (List block).
Length of ()
2.0 Length of () (operators).png
Category Operators
Type Reporter
Introduced in 1.4

The Length of () block is an Operators block and a Reporter block. The block reports how many characters the given string contains.

Note Note: Spaces count as characters in strings.

Example Uses

In certain projects, different events can happen based on the length of a value; this block is used to help.

Some common uses for the Length of () block include:

  • Checking the length of a name
ask [What's your name?] and wait
say (join (answer) (length of (answer))) for (2) secs
  • Checking how many digits there are in a player's score
say (length of (score1))
  • Chatbots, where different messages can occur depending on the length of the message that was inputted
if <(length of (answer)) < (10)> then
say [Hi!]
say [Bye!]


Main article: List of Block Workarounds

This block can be replicated with the following code:

set [length v] to [1]
repeat until <(letter ((length) + (1)) of (thing)) = []>
change [length v] by (1)

It can be flawed because it can be long and slow. This is also a problem:

set [repcount v] to (0)
repeat until <(letter ((repcount) + (1)) of (string)) = []>
add (letter ((repcount) + (1)) of (string)) to [results v]
change [repcount v] by (1)
set [length v] to (length of [results v])

It takes up lots of memory and can be slow. However, both values can be saved for later.

See Also