首页 > 解决方案 > 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

标签: lua

解决方案


function all_trim(s)
                        return s:match( "^%s*(.-)%s*$" )
                    end
                if all_trim(vehicleProps.plate) == all_trim(plate) then

将我的代码编辑如下,看来那里毕竟有一个空间,谢谢大家的帮助


推荐阅读