以指定分隔符把字符串拆分成若干子字符串.
StringSplit ( "字符串", "分隔符" [, 标志] )
字符串 | 要进行分割的字符串. |
分隔符 | 一个或多个作为分隔符的字符(区分大小写). |
标志 | [可选参数] 设置如何分割字符串,如果需要可以添加由多个标志组成的组合: 标志 = 0 (默认), 则(分隔符)字符串中的每个字符都将用于拆分字符串. 标志 = 1, 则只能以整个分隔符字符串来拆分字符串. 标志 = 2, 关闭第一个元素中的返回数量 - 方便使用 UBound() 得到此基于0开始的数组. |
Example1()
Example2()
Func Example1()
Local $aDays = StringSplit("Mon,Tues,Wed,Thur,Fri,Sat,Sun", ",") ; Split the string of days using the delimeter "," and the default flag value.
#cs
The array returned will contain the following values:
$aDays[1] = "Mon"
$aDays[2] = "Tues"
$aDays[3] = "Wed"
...
$aDays[7] = "Sun"
#ce
For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values.
MsgBox(4096, "Example1", "$aDays[" & $i & "] - " & $aDays[$i])
Next
EndFunc ;==>Example1
Func Example2()
Local $sText = "This\nline\ncontains\nC-style breaks." ; Define a variable with a string of text.
Local $aArray = StringSplit($sText, '\n', 1) ; Pass the variable to StringSplit and using the delimeter "\n". Note that flag paramter is set to 1.
#cs
The array returned will contain the following values:
$aArray[1] = "This"
$aArray[2] = "line"
...
$aArray[4] = "C-style breaks."
#ce
For $i = 1 To $aArray[0] ; Loop through the array returned by StringSplit to display the individual values.
MsgBox(4096, "Example2", "$aArray[" & $i & "] - " & $aArray[$i])
Next
EndFunc ;==>Example2