[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: String to array
From: |
Leonid Isaev (ifax) |
Subject: |
Re: String to array |
Date: |
Thu, 30 Sep 2021 14:25:42 +0000 |
User-agent: |
Mutt/1.13.4 (2020-02-15) |
On Thu, Sep 30, 2021 at 04:49:03PM +0300, Tapani Tarvainen wrote:
> On Thu, Sep 30, 2021 at 01:04:08PM +0000, Leonid Isaev (ifax)
> (leonid.isaev@ifax.com) wrote:
>
> > Something like [1]? Still a for-loop though:
> > -----8<-----
> > array=()
> > while IFS= read -r -d '' -n 1 c; do
> > array+=( "$c" )
> > done < <(printf "%s" "$string")
> > ----->8-----
> >
> > [1] https://stackoverflow.com/a/40833433
>
> Yeah, that works, but as you say it's still a loop, and neither
> simpler nor faster than the substring-based ones I posted.
Evidently, it is faster (not sure why though)...
> I may have been unclear: the solutions I posted do work, this is not a
> practical problem, I'm just curious to if there's a (reasonably)
> simple way to do it without a loop.
Converting str -> array of chars may be not practical, but looping through a
string to perform, e.g. hex encoding without external programs like xxd(1), is.
Sincerely,
--
Leonid Isaev