[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: String to array
From: |
Tapani Tarvainen |
Subject: |
Re: String to array |
Date: |
Thu, 30 Sep 2021 16:53:24 +0300 |
On Thu, Sep 30, 2021 at 03:10:54PM +0200, Alex fxmbsw7 Ratchev
(fxmbsw7@gmail.com) wrote:
> you may get success accessing str via ${str:<position>:1}
>
> s=ab34 i=-1 e=${#s} r= ; while (( n = ++i + 1 <= e )) ; do r+="pos $n char
> ${s:i:1}|" ; done ; printf %s\\n "${r%|}"
>
> pos 1 char a|pos 1 char b|pos 1 char 3|pos 1 char 4
>
> $n is a bug of 1 but you may get the point
Yes, well, that is basically same as the second one I posted:
> > array=()
> > i=0
> > while (( i < ${#string} ))
> > do
> > array+=("${string:$((i++)):1}")
> > done
Nothing wrong in that, it works, I'm just for fun looking for
different solutions without an explicit loop.
--
Tapani Tarvainen
- String to array, Tapani Tarvainen, 2021/09/30
- Re: String to array, Leonid Isaev (ifax), 2021/09/30
- Re: String to array, Alex fxmbsw7 Ratchev, 2021/09/30
- Re: String to array, Greg Wooledge, 2021/09/30
- Re: String to array, Tapani Tarvainen, 2021/09/30
- Re: String to array, Greg Wooledge, 2021/09/30
- Re: String to array, Greg Wooledge, 2021/09/30
- Re: String to array, Alex fxmbsw7 Ratchev, 2021/09/30
- Re: String to array, Greg Wooledge, 2021/09/30
- Re: String to array, Alex fxmbsw7 Ratchev, 2021/09/30