July 2018
Beginner
202 pages
5h 42m
English
There are two ways to get the length of a string, either using the string.len() function, or by placing a # symbol in front of the string. Both methods work the same way, and they both return a number value. This number can be assigned to a variable or used in its place. You can call either method on a variable, or directly on a string. The following code demonstrates all of these concepts:
hello = "hello, world"-- Assign length to variablescount_hash = #hello;count_func = string.len(hello)print ("The string:")print (hello)-- Print the variables assigned at the topprint ("Has a length of:")print (count_hash)print(count_func)-- Use string literals, in placeprint (#"hello, world")print (string.len("hello, world"))