2017-10-24 08:27 AM
Hi
There is a requirement to fetch first string present in the met-key web.page. The web.page meta-key value looks something like below. The length of the string is variable in nature and the number of strings can be variable in nature.
web.page="/String01/String02/String03.aspx"
I need to get only the first string (String01) as an additional meta-key (lets say meta_new). Please let me know how can I achieve this using LUA parser.
Regards
Shrinidhi Shastry##
2017-10-24 09:09 AM
This should do it.
local getFirstString = nw.createParser("getFirstString", "")
getFirstString:setKeys({
nwlanguagekey.create("meta_new")
})
function getFirstString:onMeta(idx, vlu)
if vlu then
local firstString = string.match(vlu, "^/([^/]+)/")
if firstString then
nw.createMeta(self.keys["meta_new"], firstString)
end
end
end
getFirstString:setCallbacks({
[nwlanguagekey.create("web.page")] = getFirstString.onMeta
})
2017-10-24 09:24 AM
Another way I had tried in the past I commented on in a previous post.
https://community.rsa.com/message/881599?commentID=881599#comment-881599
Chris
2017-10-24 09:51 AM
Hi William
Thanks for the code. I am able to populate the first string. Thanks for the quick help.
Regards
Shrinidhi Shastry