Home >>VB.Net Built-in Functions >VB.Net program to demonstrate the Mid() function

VB.Net program to demonstrate the Mid() function

Write a VB.Net program to demonstrate the Mid() function

The Mid() function is used to extract a substring from the given string specified.

Syntax :

Mid(str, pos, n)

Parameters :

  • Str : specified string
  • Pos : position from where substring gets extracted.
  • N : The character number is extracted from the string.

Program :

Below is the source code for demonstrating the Mid() function. The program given is compiled and successfully executed.


Module Module1
    Sub Main()
        Dim str1 As String = "I love india"
        Dim str2 As String = ""
        str2 = Mid(str1, 3, 4)
        Console.WriteLine("Sub-string is: {0}", str2)
    End Sub
End Module
	
Output:
Sub-string is: love

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created two variables str1 and str2, in the Main() step, here variable str1 is initialize with "I love india" and variable str2 with a blank string is initialized.

str2 = Mid(str1, 3, 4)

We extracted the substring from str1 in the above code, and assigned it to str2. Then, on the console screen, we printed an extracted substring.


No Sidebar ads