VB.NET tutorial- StartsWith EndsWith and Split


String Manipulation

StartsWith EndsWith and Split Functions


StartsWith function
The StartsWith function tests whether a string starts with a specified string or not. It returns true or false.
Example:
Module Module1
 
    Sub Main()
        Dim str1 As New String("Hello World")
        If str1.StartsWith("Hello") Then
            Console.WriteLine("str1 starts with Hello")
        Else
            Console.WriteLine("str1 doesn't start with Hello")
        End If
        Console.ReadLine()
    End Sub
 
End Module
 


EndsWith function
The EndsWith function tests whether a string ends with a specified string or not. It returns true or false.
Example:
Module Module1
 
    Sub Main()
        Dim str1 As New String("Hello World")
        If str1.EndsWith("Hello") Then
            Console.WriteLine("str1 ends with Hello")
        Else
            Console.WriteLine("str1 doesn't end with Hello")
        End If
        Console.ReadLine()
    End Sub
 
End Module
 


Split function

The split function splits a string to an array of strings.

st=Str.Split(separator)
Example:
Module Module1
 
    Sub Main()
        Dim str1 As New String("Hello World")
        Dim str2() As String = str1.Split(" ") 'split str1 by white space
        For Each s In str2
            Console.WriteLine(s)
        Next
        Console.ReadLine()
    End Sub
 
End Module


Comments

CAPTCHA image




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.