[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Filtering chars from string
- From: Scott Morgan <blumf@...>
- Date: Tue, 27 Aug 2019 09:53:52 +0100
What's the best way to filter out non-specified chars from an ASCII
string? (so no need to worry about UTF8, etc.)
local allowed = "AbC"
local txt = "dDcCbBaA"
filter(txt, allowed, "") -- ret: "CbA"
filter(txt, allowed, "?") -- ret: "???Cb??A"
For extra difficulty, plain Lua 5.1, no modules (lpeg, etc.)
I can see a way using gsub(txt, ".", filter_func), but was wondering if
there are any tricks that might make it simpler.