Split()

Namespace ›› System ›› MfString ›› Methods ››
Parent Previous Next

Split()

OutputVar := instance.Split()
OutputVar := instance.Split(separator)
OutputVar := instance.Split(separator, options)

Split()

Splits the current string into all it characters.

Split(separator)

Splits the string into part by characters in separator.

Split(separator, options)

Splits the string into parts by characters with options.

Parameters

separator

A string of characters to split the current instance of MfString by.
Can be string var or a MfString object instance.

options

MfStringSplitOptions options.
Can be Integer, MfStringSplitOptions instance, or MfStringSplitOptions.Instance.EnumValue

Returns

Returns a MfGenericList of MfString containing all the instance of string found in the split.

Throws

Throws MfException on General errors.
Throws MfArgumentException if there is an error get a value from a parameter.

Remarks

Method always returns a MfGenericList of MfString. The ReturnAsObject instance of each MfString instance in the MfGenericList is set to the same value of ReturnAsObject for the current instance of MfString.

Overloads method supports using all vars or all objects. Mixing of vars and Objects is supported for this method.

Variadic Method; This method is Variadic so you may construct an instance of MfParams containing any of the overload method parameters listed above and pass in the MfParams instance to the method instead of using the overloads described above. See MfParams for more information.

Example

; ------------------------------------------------------------------------------
MyStr := new MfString()
MyStr.Append("Hello World")
SplitResult := MyStr.Split() ; no options split in to single characters
mfsResult := new MfString()

for i, mfs in SplitResult
{
   mfsResult.AppendLine(MfString.Format("Result '{0}': {1}", i, mfs.Value))
}

MsgBox % mfsResult.Value

/*
Result '0': H
Result '1': e
Result '2': l
Result '3': l
Result '4': o
Result '5':  
Result '6': W
Result '7': o
Result '8': r
Result '9': l
Result '10': d

*/

; ------------------------------------------------------------------------------
MyStr := new MfString()
MyStr.Append("Hello World")
; Split all characters but remove any whitespace characters
SplitResult := MyStr.Split("", MfStringSplitOptions.Instance.RemoveEmptyEntries)
mfsResult := new MfString()

for i, mfs in SplitResult
{
   mfsResult.AppendLine(MfString.Format("Result '{0}': {1}", i, mfs.Value))
}

MsgBox % mfsResult.Value

/*
Result '0': H
Result '1': e
Result '2': l
Result '3': l
Result '4': o
Result '5': W
Result '6': o
Result '7': r
Result '8': l
Result '9': d

*/

; ------------------------------------------------------------------------------
MyStr := new MfString()
MyStr.Append("Hello| |World")
SplitResult := MyStr.Split("|", MfStringSplitOptions.Instance.RemoveEmptyEntries)
mfsResult := new MfString()

for i, mfs in SplitResult
{
   mfsResult.AppendLine(MfString.Format("Result '{0}': {1}", i, mfs.Value))
}

MsgBox % mfsResult.Value

/*
Result '0': Hello
Result '1': World

*/

; ------------------------------------------------------------------------------
MyStr := new MfString()
MyStr.Append("Hello| |World")
SplitResult := MyStr.Split("|", 1) ; 1 = MfStringSplitOptions.Instance.RemoveEmptyEntries.Value
mfsResult := new MfString()

for i, mfs in SplitResult
{
   mfsResult.AppendLine(MfString.Format("Result '{0}': {1}", i, mfs.Value))
}

MsgBox % mfsResult.Value

/*
Result '0': Hello
Result '1': World

*/

; ------------------------------------------------------------------------------
MyStr := new MfString()
MyStr.Append("Hello| |World")
SplitResult := MyStr.Split("|")
mfsResult := new MfString()

for i, mfs in SplitResult
{
   mfsResult.AppendLine(MfString.Format("Result '{0}': {1}", i, mfs.Value))
}

MsgBox % mfsResult.Value

/*
Result '0': Hello
Result '1':  
Result '2': World

*/