简体   繁体   English

Lua String连接

[英]Lua String concatenation

I am working on Lua and I have this kind of code 我正在研究Lua,我有这种代码

MapMessage(Process["ks.MSH"][1], MsgIn, mg)
MapEvent(Process["ks.EVN"][1], MsgIn, mg)
MapPatient(Process["ks.PID"][1], MsgIn, mg)
MapVisit(Process["ks.PV1"][1],MsgIn,mg)

In above statements, MapMessage, MapEvent, MapPatient, MapVisit are the functions and ks.MSH, ks.EVN, ks.PID, ks.PV1 are the tables in the database. 在上面的语句中,MapMessage,MapEvent,MapPatient,MapVisit是函数,ks.MSH,ks.EVN,ks.PID,ks.PV1是数据库中的表。 Now, I want to automate a part of this process using gmatch function provided in lua and I have this so far 现在,我想使用lua中提供的gmatch函数自动执行此过程的一部分,到目前为止我已经这样做了

for u in string.gmatch(S, "([^,%s]+)"), 1 do
     l[k] = u 
    _G["Map"..l[k]](Process["ks[l[k]]"][1], R[1])
     k=k+1
   end 

but the concatenation part in the third line of above code is not really making it ks.MSH, ks.PID, ks.PV1 etc, so please suggest what needs to be there in place of (Process["ks[l[k]]"][1] to get s.MSH, ks.PID, ks.PV1 etc 但是上面代码第三行中的连接部分并没有真正使它成为ks.MSH,ks.PID,ks.PV1等,所以请建议代替那里需要的东西(Process["ks[l[k]]"][1]得到s.MSH,ks.PID,ks.PV1等

Since your string contains "MSH, PID, PV1, EVN" , you'd have to use a hash-table or a lookup table. 由于您的字符串包含"MSH, PID, PV1, EVN" ,因此您必须使用哈希表或查找表。 The program would be something like this: 该计划将是这样的:

S = "MSH, PID, PV1, EVN"
tLookup = {
    MSH = "Message",
    EVN = "Event",
    PID = "Patient",
    PV1 = "Visit",
}

for u in S:gmatch "([^,%s]+)" do
    sNameOfFunction = tLoopup[u]
    _G[ "Map"..sNameOfFunction ] ( Process["ks."..u][1], MsgIn, mg )
     k=k+1
end

Or even something like this: 甚至是这样的:

S = "MSH, PID, PV1, EVN"
tLookup = {
    MSH = _G.MapMessage,
    EVN = _G.MapEvent,
    PID = _G.MapPatient,
    PV1 = _G.MapVisit,
}

for u in S:gmatch "([^,%s]+)" do
    tLoopup[u] ( Process["ks."..u][1], MsgIn, mg )
    k = k+1
end

@Egor, No since I have double quotes around as well, it's not working, Please have a closer look , (Process["ks.PV1"][1],MsgIn,mg) , This is what exactly I need @Egor,不,因为我也有双引号,它不起作用,请仔细看看,(Process [“ks.PV1”] [1],MsgIn,mg),这正是我需要的


ks = {Message = "ks.MSH", Event = "ks.EVN", Patient = "ks.PID", Visit = "ks.PV1"}
S = "Message, Event, Patient, Visit"
l = {}
k = 1
for u in string.gmatch(S, "([^,%s]+)") do
   l[k] = u 
   _G["Map"..l[k]](Process[ks[l[k]]][1], MsgIn, mg)
   k=k+1
end

Here is what finally worked, thanks Egor and hjpotter92 :) 这是最终工作的,感谢Egor和hjpotter92 :)

ks = {MSH = "ks.MSH", EVN = "ks.EVN", PID = "ks.PID", PV1 = "ks.PV1", PV2 = "ks.PV2"}
S = tostring(R[1].AllSegmentsList)
 l = {}
k = 1
for u in string.gmatch(S, "([^,%s]+)") do
 l[k] = u 
 _G["Map"..l[k]](Process[ks[l[k]]][1], MsgIn, mg)
   k=k+1
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM