Search code examples
arraysstringautoit

Equivalent of Join in AutoIt


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>")

Solution

  • 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.