help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Fastest way to join an array into a string


From: Peng Yu
Subject: Re: [Help-bash] Fastest way to join an array into a string
Date: Mon, 26 Aug 2019 19:12:40 -0500

It seems that this will be slower as it involves many string
replacement operations, whereas my version does not involve any string
replacement.

> # https://stackoverflow.com/a/17841619/1236063
> # $1 is the delimiter
> # $2-n are the args to join
> underpin::join_by() {
>   local delimiter=$1
>   shift
>   echo -n "$1"
>   shift
>   # inserts the delimiter at the beginning of each arg
>   printf '%s' "${@/#/$delimiter}"
> }

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]