【问题标题】:Lua string.find not working with decimalLua string.find 不使用小数
【发布时间】:2013-12-06 04:11:45
【问题描述】:
pos = string.find("1.23x", ".")
print ( pos )

我总是得到 1,而输出应该是 2。即使我尝试这个

pos = string.find("123x", ".")
print ( pos )

它仍然返回 1。

我做错了什么?

【问题讨论】:

标签: string lua


【解决方案1】:

忘记了 Lua 可以使用模式,这是可行的:

pos = string.find('1.23x', '.',1 ,true)
print ( pos )

点作为模式匹配,第四个参数将模式设置为普通字符,因此它将点识别为常规字符。

【讨论】:

  • 或者你可以像这样逃避.pos = string.find("1.23x", "%.")
猜你喜欢
  • 2017-03-01
  • 2017-08-08
  • 2021-11-02
  • 1970-01-01
  • 1970-01-01
  • 2011-03-12
  • 2014-08-04
  • 2016-02-13
  • 1970-01-01
相关资源
最近更新 更多