|
Sorry, I was not precise enough, and thanks for your hints. What you suggest is exactly what I have (so I feel very proud). I need to iterate four times because the subs need to be appied in a certain order: some characters are the equivalent of four tokens, e.g., the sequence >~h| translates to character 1x1FC7. Some consist of three tokens (>~h ==> 1x1FC6), some of two, some of one. Now I found this sentence in one of the tutorials: "Note, there is no guarantee as to the order in which keys will be stored in a table when using dictionaries so the order of retrieval of keys using pairs() is not guaranteed." That's why I think I need four iterations. Or am I off- track here?I'm afraid you're about to do something the hard way, so forgive me if I misunderstood you. Here is what you probably should do (and what I meant earlier): ======== #!/usr/local/bin/lua local subs = { a = "α", b = "β" ---... } local function mysubs(lines) for i,v in pairs(subs) do lines = string.gsub(lines, i, v); end; return lines; end; file = io.stdin:read("*all"); file = string.gsub(file, "localgreek(%b{})", function(lines) return "localgreek"..mysubs(lines); end); io.stdout:write(file); ======= HTH,
Thanks Thomas