LUA笔记之字符串

LUA提供了自动数值转换, 基本上说是乱来也不为过, 就当做是不熟悉数据结构吧, 例子:

print("10" + 1)           --> 11
print("10 + 1")           --> 10 + 1
print("-5.3e-10"*"2")     --> -1.06e-09
print("hello" + 1)        -- ERROR (cannot convert "hello")

我个人比较关心字符串的处理, 比如最简单的字符串转换拼凑:

    print(10 .. 20)        --> 1020

可以看出 .. 可以自动转成字符串, 并拼在一起.

忘掉java的equals, 直接用==可以判断字符串是否相等, 这也很重要:

    print(tostring(10) == "10")   --> true
    print(10 .. "" == "10")       --> true

tostring跟..""一个疗效.





原文地址:https://www.cnblogs.com/Montauk/p/5457874.html