lua - Lua if 返回 false 但应该返回 true
问题描述
所以我有这段代码
for i=1, #result, 1 do
local vehicleProps = json.decode(result[i].vehicle)
print(vehicleProps.plate)
print(plate)
if vehicleProps.plate == plate then
found = true
print(found)
break
end
print(found)
end
我得到的输出是
UCF 804
864539
false
65507
864539
false
864539
864539
false
我对 Lua 很陌生,但它很简单,但我不明白为什么当 vehicleProps.plate 等于 plate 时,代码返回 false?有什么方法可以检查两个值是否相同?我会在这里提供任何类型的帮助。
用户输出:hjpotter92
2162899082 417849 string string false
QBW 339 417849 string string false
27538 417849 string string false
UCF 804 417849 string string false
417849 417849 string string false
65507 417849 string string false
864539 417849 string string false
9703143430 417849 string string false
解决方案
function all_trim(s)
return s:match( "^%s*(.-)%s*$" )
end
if all_trim(vehicleProps.plate) == all_trim(plate) then
将我的代码编辑如下,看来那里毕竟有一个空间,谢谢大家的帮助
推荐阅读
- java - 日食 | 尝试在 Ubuntu 下打开 sh 文件时权限被拒绝
- python - 从 python 调用任务运行 unittest.main()
- ethereum - ropsten.infura.io 引发 405 错误
- gem5 - 使用 Gem5 进行数据模式分布分析
- python - 从 matplotlib.patches 中的 CirclePolygon 获取坐标
- java - FileReader 抛出异常,因为文件路径语法错误?
- sequelize.js - Sequelize - 无法使用 Sync 设置自定义字段名称({alter: true})
- eclipse - 在 src/test/resources 下的 maven 项目中创建文件夹
- java - 在 pom.xml 中传递 VM 参数
- python - swagger API - 创建一个完美的请求