[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Filtering chars from string
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 27 Aug 2019 06:44:56 -0300
On Tue, Aug 27, 2019 at 5:55 AM Scott Morgan <blumf@blueyonder.co.uk> wrote:
>
> 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"
function filter(t,a,r)
print((t:gsub("[^"..a.."]",r)))
end