Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

lua
communitycreator

What is string.len in Lua?

Dario Vincenzo Tarantini

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In Lua, the string.len() function is used to get the size of a string.

Here is a visual representation of this function:

%0 node_1 Hello, Educative! node_3 string.len() node_1->node_3 node_1635967162535 17 node_3->node_1635967162535
Visual representation of the len() function

Syntax

string.len(str)

Parameters

  • The function needs a string as a mandatory parameter.

Return value

  • The function will return the size of the string as an integer.

Example

In this example, we will return the size of our string.

mystr = "Hello, Educative!"
print(string.len(mystr))

Expected output

17

RELATED TAGS

lua
communitycreator

CONTRIBUTOR

Dario Vincenzo Tarantini

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring