Separates a string into an array of substrings using the specified delimiters.
Array := StrSplit(String , Delimiters, OmitChars, MaxParts)
A string to split.
If this parameter is blank or omitted, each character of the input string will be treated as a separate substring.
Otherwise, Delimiters can be either a single string or an array of strings, each of which is used to determine where the boundaries between substrings occur. Since the delimiters are not considered to be part of the substrings themselves, they are never included in the returned array. Also, if there is nothing between a pair of delimiters within the input string, the corresponding array element will be blank.
For example: ","
would divide the string based on every occurrence of a comma. Similarly, [A_Tab, A_Space]
would create a new array element every time a space or tab is encountered in the input string.
An optional list of characters (case sensitive) to exclude from the beginning and end of each array element. For example, if OmitChars is " `t"
, spaces and tabs will be removed from the beginning and end (but not the middle) of every element.
If Delimiters is blank, OmitChars indicates which characters should be excluded from the array.
This function returns an array (object) of strings.
Whitespace characters such as spaces and tabs will be preserved unless those characters are themselves delimiters or included in OmitChars. Tabs and spaces can be trimmed from both ends of any variable by calling the Trim function. For example: MyArray1 := Trim(MyArray1)
.
To split a string that is in standard CSV (comma separated value) format, use a parsing loop since it has built-in CSV handling.
To arrange the fields in a different order prior to splitting them, use the Sort command.
If you do not need the substrings to be permanently stored in memory, consider using a parsing loop -- especially if String is very large, in which case a large amount of memory would be saved. For example:
Colors := "red,green,blue" Loop, Parse, Colors, % "," MsgBox % "Color number " A_Index " is " A_LoopField
StringSplit, Parsing loop, Arrays, Sort, SplitPath, InStr(), SubStr(), StrLen(), StringLower, StringUpper, StrReplace()