VB.NET tutorial-String Manipulation: Mid Concat and Compare


String Manipulation

Mid Concat and Compare


Mid function
The Mid function is used to get some sequential characters from a string.
Mid(Str,start_num,length)

Example:
Module Module1
 
    Sub Main()
        Dim str1 As New String("Hello World")
        Dim str2 As String
        'Get the word "World" from "Hello World"
        str2 = Mid(str1, 7, 5)
        Console.WriteLine(str2)
 
        Console.ReadLine()
    End Sub
 
End Module
 


Copy function
The Copy function is used to copy the content of a string to another string.
str2=String.Copy(str1)
 
Example:
Module Module1
 
    Sub Main()
        Dim str1 As New String("Hello World")
        Dim str2 As String
        str2 = String.Copy(str1) 'copy the content of str1 to str2
        Console.WriteLine(str2)
 
        Console.ReadLine()
    End Sub
 
End Module
 


Compare function
The Compare function is used to compare two strings. It returns zero if the first string is the same as the second string. Otherwise, it returns -1 or 1.
result=String.Compare(str1,str2)
 
Example:
 
 
Module Module1
 
    Sub Main()
        Dim str1 As New String("Hello World")
        Dim str2 As New String("Hello World")
        Dim result As Integer
        result = String.Compare(str1, str2) 'compare str1 and str2
        Console.WriteLine(result)
 
        Console.ReadLine()
    End Sub
 


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.