.len()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Jul 5, 2024
Contribute to Docs

The .len() method returns the total number of characters present in a specified string.

Syntax

string.len(s)
  • s: The input string whose length is to be determined.

Note: Calling string.len() without any arguments will result in an error.

Example

The following example demonstrates the usage of the .len() method:

town = "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch"
lenExample = string.len(town)
print(lenExample)

The above code produces the following output:

58

All contributors

Looking to contribute?

Learn Lua on Codecademy