VB.NET SubString

In this article you will learn How to get a substring from a string in VB.NET.
  • 4902

String.Substring method retrieves a substring from a string. If you do not specify any parameters in this method, it will retrieve first sub string. You can also specify the starting index and number of characters in a substring you want to retrieve.

The following code snippet gets a string starting at index 0 (first character) to next 12 characters in a string. If a string has less than 12 characters, you will see an exception.

    Dim authorsString As String = "Mahesh Chand, Mike Gold, Raj Beniwal, Praveen Kumar"

    // Get a substring strating at 0th index to next 12 characters
    Dim mahesh As String = authorsString.Substring(0, 12)
    Console.WriteLine(mahesh)

     // Get all substrings separated by Space
    Dim commaSeparator As Char() = New Char() {","c}
    Dim authors As String() = authorsString.Split(commaSeparator, StringSplitOptions.None)
    For Each author As String In authors
        Console.WriteLine(author)
    Next
    Console.ReadKey()

Conclusion

Hope this article would have helped you in understanding
How to get a substring from a string in VB.NET.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.