string.len()

Type Function
Library string.*
Return value Number
Revision Release 2024.3703
Keywords string, len, length, string length
See also String

Overview

Returns the length of a string (amount of characters).

Gotchas

If you're using encoded UTF-8 characters, for example Russian or Arabic characters, some of these characters are multi-byte and may vary between 2 and 4 characters when read by string.len(). Please see here for more information on UTF-8 encoding.

Syntax

string.len( s )

s:len()
s (required)

String. Any string.

Example

print( string.len( "Lua" ) )          --> 3
print( string.len( "" ) )             --> 0
print( string.len( "Lua\000user" ) )  --> 8