官术网_书友最值得收藏!

String length

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 variables
count_hash = #hello;
count_func = string.len(hello)
print ("The string:")
print (hello)
-- Print the variables assigned at the top
print ("Has a length of:")
print (count_hash)
print(count_func)
-- Use string literals, in place
print (#"hello, world")
print (string.len("hello, world"))
主站蜘蛛池模板: 屏山县| 佳木斯市| 萨迦县| 广丰县| 通河县| 广宗县| 古蔺县| 栖霞市| 咸宁市| 苍南县| 博客| 雅江县| 深泽县| 得荣县| 三都| 南雄市| 望城县| 若羌县| 澄迈县| 尉氏县| 康平县| 买车| 珲春市| 兴仁县| 阜新市| 清苑县| 滨海县| 高要市| 大邑县| 曲麻莱县| 多伦县| 连平县| 邓州市| 边坝县| 长垣县| 扶余县| 阿克| 涞源县| 正镶白旗| 怀宁县| 海淀区|