相当于 AutoIt 中的 Join
Equivalent of Join in AutoIt
AutoIt 有一个 StringSplit 函数,它的工作方式与 C# 或 Visual Basic 中的 Split 类似,但我找不到使用中间某个字符串连接字符串数组的等价物。
所以我想要 AutoIt 相当于 Visual Basic:
strResult = Join(strSplit, "<joiner>")
您可以使用字符串连接符连接字符串输入数组的每个元素。请参阅下面的示例。
函数:
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
测试:
$string = "some;text;here"
$split = StringSplit($string,";",2)
$res = Join($split,"--")
ConsoleWrite($res & @CRLF)
_ArrayToString
Places the elements of a 1D or 2D array into a single string, separated by the specified delimiters
示例:
#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.
AutoIt 有一个 StringSplit 函数,它的工作方式与 C# 或 Visual Basic 中的 Split 类似,但我找不到使用中间某个字符串连接字符串数组的等价物。
所以我想要 AutoIt 相当于 Visual Basic:
strResult = Join(strSplit, "<joiner>")
您可以使用字符串连接符连接字符串输入数组的每个元素。请参阅下面的示例。
函数:
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
测试:
$string = "some;text;here"
$split = StringSplit($string,";",2)
$res = Join($split,"--")
ConsoleWrite($res & @CRLF)
_ArrayToString
Places the elements of a 1D or 2D array into a single string, separated by the specified delimiters
示例:
#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.