3
我需要在Lua停止讀取換行符後獲取模式幫助。 我的代碼:腳本Lua模式在行結束時停止
function getusers(file)
local list, close = {}
local user, value = string.match(file,"(UserName=)(.*)")
print(value)
f:close()
end
f = assert(io.open('file2.ini', "r"))
local t = f:read("*all")
getusers(t)
--file2.ini--
user=a
UserName=Tom
Password=xyz
UserName=Jane
輸出使用file2.ini:
湯姆
密碼= XYZ
用戶名=簡
如何獲得模式到達行結束後停止?
工作正常。謝謝。 – Pekinese 2014-10-02 14:49:15
確保文件以換行符結尾... – lhf 2014-10-02 14:49:19
或使用'「(UserName =)([^ \ n] *)」'或甚至是「(UserName =)(%w *)」 – siffiejoe 2014-10-02 15:16:03