.len()

ivaaane's avatar
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

Contribute to Docs

Learn Lua on Codecademy