【发布时间】:2020-12-27 08:21:20
【问题描述】:
所以在我正在编写的 LUA 驱动程序中,我不断收到 RS232 字符串,例如; ZAA1、ZO64、D1 等等等。我正在寻找一个解决方案来查找字符串在哪里结束,而 Int 开始并将其放入两个不同的变量中? 我目前正在使用带有 string.match 方法的 while 循环。有没有更好的办法?当前缩短代码如下;
s = "ZO29"
j = 1
while j <= 64 do
if (s == string.format("ZO%d", j)) then
print("Within ZO message")
inputBuffer = ""
sendACK()
break
elseif (s == string.format("ZC%d", j)) then
inputBuffer = ""
sendACK()
break
end
j = j + 1
end
【问题讨论】: