哪句话中包含'indexOf'这个词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计259个文字,预计阅读时间需要2分钟。
在Lua中遇到问题,检查字符串值是否未在另一个字符串中显示。在JavaScript中可能会这样操作:`'my string'.indexOf('no-cache')===-1 // true`。但在Lua中,我尝试使用字符串模块,但这样给了错误提示。
我在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)
本文共计259个文字,预计阅读时间需要2分钟。
在Lua中遇到问题,检查字符串值是否未在另一个字符串中显示。在JavaScript中可能会这样操作:`'my string'.indexOf('no-cache')===-1 // true`。但在Lua中,我尝试使用字符串模块,但这样给了错误提示。
我在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)

