1

AutoIt has a function StringSplit that works just like Split in C# or Visual Basic, but I can't find the equivalent of joining an array of strings using a certain string in between.

So I would like to have the AutoIt equivalent of Visual Basic:

strResult = Join(strSplit, "<joiner>")
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ib11
  • 2,530
  • 3
  • 22
  • 55

2 Answers2

2

You can concatenate each element of the input array of strings with string joiner. See example below.

Function:

Func Join($aSplit,$joiner)
    if not isarray($aSplit) then return 0

    local $res = ""

    for $i = 0 to UBound($aSplit)-1
        $res &= $aSplit[$i] & $joiner
    Next

    $res = StringTrimRight($res,StringLen($joiner))
    return $res
EndFunc

Testing:

$string = "some;text;here"
$split = StringSplit($string,";",2)

$res = Join($split,"--")
ConsoleWrite($res & @CRLF)
matrix
  • 513
  • 3
  • 8
2

As per documentation:

_ArrayToString
Places the elements of a 1D or 2D array into a single string, separated by the specified delimiters

Example:

#include <Array.au3>

Global Const $g_aArray     = ['A', 'B', 'C']
Global Const $g_sDelimiter = '<joiner>'
Global Const $g_sString    = _ArrayToString($g_aArray, $g_sDelimiter)

ConsoleWrite($g_sString & @CRLF)

Returns:

A<joiner>B<joiner>C

Related.

user4157124
  • 2,809
  • 13
  • 27
  • 42