Lua .len()
Published Jul 5, 2024Updated Aug 24, 2025
Contribute to Docs
The .len() method returns the length of a string, measured in bytes. It is equivalent to using the length operator (#).
Syntax
string.len(s)
s: The input string whose length is to be determined.
Note: Calling
.len()without any arguments will result in an error.
Example
The following example demonstrates the usage of the .len() method:
hello = "hello"hello_len = string.len(hello)print(hello_len)
The above code produces the following output:
5
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Lua on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
- Beginner Friendly.4 hours