[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: String to array
From: |
Greg Wooledge |
Subject: |
Re: String to array |
Date: |
Thu, 30 Sep 2021 13:03:43 -0400 |
On Thu, Sep 30, 2021 at 06:51:50PM +0200, Alex fxmbsw7 Ratchev wrote:
> i dunno but i did string=hello and a time while i 10k and 1k, in 3s neither
> finished
> hm may be proot cellfone slowness
This thread is not about speed. The OP wanted to experiment with
different solutions that are explicitly *not* optimal, for fun.
If you want a fast solution, just use a loop:
unset array
n=${#string}
for ((i=0; i<n; i++)); do array[i]=${string:i:1}; done
unicorn:~$ unset array; n=${#string}; for ((i=0; i<n; i++)); do
array[i]=${string:i:1}; done
unicorn:~$ declare -p array
declare -a array=([0]="h" [1]="i" [2]=" " [3]="b" [4]="y" [5]="e" [6]=$'\t'
[7]="w" [8]="h" [9]="y" [10]=$'\n' [11]=$'\E' [12]="[" [13]=";" [14]="1")
- Re: String to array, (continued)