Skip to content

Split method

Xusinboy Bekchanov edited this page Oct 30, 2023 · 3 revisions

Returns a zero-based, one-dimensional array containing a specified number of substrings.

Syntax

Split(expression, delimiter, result, [ matchcase ]]])

The Split function syntax has these named arguments:

Part Description
expression Required. String expression containing substrings and delimiters. If expression is a zero-length string(""), Split returns an empty array, that is, an array with no elements and no data.
delimiter String character used to identify substring limits. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.
result Variable where the result is returned.
matchcase Optional. Boolean value indicating the kind of comparison to use when evaluating substrings.

Example

This example shows how to use the Split method.

#include "mff/UString.bi"

Dim strFull As String
Dim arrSplitStrings1() As String
Dim arrSplitStrings2() As String
Dim strSingleString1 As String
Dim strSingleString2 As String
Dim i As Long

strFull = "Dow - Fonseca - Graham - Kopke - Noval - Offley - Sandeman - Taylor - Warre"    ' String that will be used. 

Split(strFull, "-", arrSplitStrings1())     ' arrSplitStrings1 will be an array from 0 To 8. 
                                            ' arrSplitStrings1(0) = "Dow " and arrSplitStrings1(1) = " Fonesca ". 
                                            ' The delimiter did not include spaces, so the spaces in strFull will be included in the returned array values. 

Split(strFull, " - ", arrSplitStrings2())   ' arrSplitStrings2 will be an array from 0 To 8. 
                                            ' arrSplitStrings2(0) = "Dow" and arrSplitStrings2(1) = "Fonesca". 
                                            ' The delimiter includes the spaces, so the spaces will not be included in the returned array values. 

'Multiple examples of how to return the value "Kopke" (array position 3). 

strSingleString1 = arrSplitStrings2(3)      ' strSingleString1 = "Kopke". 

For i = LBound(arrSplitStrings2, 1) To UBound(arrSplitStrings2, 1)
    If InStr(1, arrSplitStrings2(i), "Kopke") > 0 Then
        strSingleString2 = arrSplitStrings2(i)
        Print strSingleString2
        Exit For
    End If 
Next i

Sleep

See also

Clone this wiki locally