How to VB.NET String.Split()

The VB.Net Split() extracts the substrings from the given string that are delimited by the separator parameter, and returns those substrings as elements of an array.


If your String contains "dd-mm-yy", split on the "-" character to get an array of: "dd" "mm" "yy".

If the separator parameter is null or contains no characters, white space characters are assumed to be the delimiters.

Syntax :


  1. separator - the given delimiter.


  1. An array of Strings delimited by one or more characters in separator.


VB.Net String Split Example

VB.Net String Split by multiple characters delimiter

We can split a string by multiple character delimiter using String.split() method.


Using Regular Expressions for multiple characters

VB.Net String Split by multiple characters delimiter using Regular Expressions

You should import System.Text.RegularExpressions in your project to run the following code


Split() a delimited string to a List < String > in VB.Net

You can retrieve the result of a String splt() method to a VB.Net List. The following program convert the String Array to a List.

VB.Net Convert List to String

VB.NetString split White spaces

StringSplitOptions.RemoveEmptyEntries guarantees the return value does not include array elements that contain an empty string. The following VB.Net program shows how to remove all white spaces from string using StringSplitOptions.RemoveEmptyEntries.

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myStrA As String = "one two   three    four     five"
        Dim result As String() = myStrA.Split(New Char(-1) {}, StringSplitOptions.RemoveEmptyEntries)
        For Each s As String In result
    End Sub
End Class

When you execute this VB.Net program you will get the result removing all white spaces from the string (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About