加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Lua – 获取indexOf字符串

发布时间:2020-12-15 00:25:26 所属栏目:大数据 来源:网络整理
导读:我在Lua中遇到问题,检查字符串值是否未在另一个字符串中显示. 这就是我在Javascript中可能会这样做的方式: 'my string'.indexOf('no-cache') === -1 // true 但在Lua我试图使用字符串模块,这给了我意想不到的响应: string.find('my string','no-cache') --
我在Lua中遇到问题,检查字符串值是否未在另一个字符串中显示.

这就是我在Javascript中可能会这样做的方式:

'my string'.indexOf('no-cache') === -1 // true

但在Lua我试图使用字符串模块,这给了我意想不到的响应:

string.find('my string','no-cache') -- nil,that's fine but..
string.find('no-cache','no-cache') -- nil.. that's weird
string.find('no-cache','no') -- 1,2 here it's right.. strange..

解决方法

正如已经提到的那样,– 是模式元字符,specifically:
  • a single character class followed by ‘-‘,which also matches 0 or more repetitions of characters in the class. Unlike ‘*’,these repetition items will always match the shortest possible sequence;

您可能对string.find的普通选项感兴趣.这将避免将来转义任何其他内容.

string.find('no-cache','no-cache',1,true)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读