Filtering chars from string
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Filtering chars from string
- From: Scott Morgan <blumf@...>
- Date: 2019年8月27日 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.)
e.g.:
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.
Scott