首页 > lua的字符串操作的问题

lua的字符串操作的问题

1.平时都是用string库,今天见识了下面这样用法:

local str = "hello world"
print(str:sub(1))

------

结果为:hello world


平时的用法:
local str = "hello world"
print(string.sub(str,1))

------

结果为:hello world

请问 “字符串:sub()”这种用法的出处或资料有人知道吗?


使用冒号将默认接收一个self参数,而使用点号则需要显式传入self参数

https://moonbingbing.gitbooks.io/openresty-best-practices/content/lua/dot_diff.html


这是因为lua的”语法糖的原因“


可以看下完整的lua程序设计2,我目前也正在学习,里面有详细的介绍

【热门文章】
【热门文章】