Method: Split for VBS
- Updated2024-09-12
- 1 minute(s) read
Methods > Method: Split for VBS
Method: Split for VBS
Searches, in a text, for delimiters and generates a one-dimensional, zero-based array containing substrings.
vSplit = Object.Split(expression, [delimiter], [count], [compare])
| Object | VBS Object with this method. You do not need to specify this object. |
| expression | Variant Specifies the text you want to split. |
| [delimiter] | Variant Specifies the delimiter. If you do not specify a value, the Split method uses a blank (" "). |
| [count] | Variant Specifies the number of substrings to be returned. If you do not specify count, the Split method uses the value -1, and returns all substrings. |
| [compare] | Variant Specifies the type of comparison. Possible settings are vbBinaryCompare and vbTextCompare. If you do not specify compare, the Split method performs a binary comparison. |
| vSplit | Variant Receives a one-dimensional, zero-based array that contains substrings. |
The following example splits the text DIAdemXisXgreat at the character X and generates an array that contains three strings:
Dim MyString, MyArray, i MyString = "DIAdemXisXgreat" MyArray = Split(MyString, "X", -1,vbTextCompare) ' MyArray(0) contains "DIAdem" ' MyArray(1) contains "is" ' MyArray(2) contains "great" For i = 0 to UBound(MyArray) Call MsgBox(MyArray(i)) Next