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.


VB.Net Built-in Functions VB.Net program to demonstrate the InStr() function VB.Net program to demonstrate the UCase() function VB.Net program to demonstrate the LCase() function VB.Net program to demonstrate the Chr() function VB.Net program to demonstrate the Asc() function VB.Net program to demonstrate the Hex() function VB.Net program to demonstrate the Oct() function VB.Net program to demonstrate the Fix() function VB.Net program to demonstrate the CInt() function VB.Net program to demonstrate the CSByte() function VB.Net program to demonstrate the CShort() function VB.Net program to demonstrate the CUShort() function VB.Net program to demonstrate the CByte() function VB.Net program to demonstrate the CSng() function VB.Net program to demonstrate the CDbl() function VB.Net program to demonstrate the CDec() function VB.Net program to demonstrate the CLng() function VB.Net program to demonstrate the CULng() function VB.Net program to demonstrate the CStr() function VB.Net program to print date and time in 'dd/mm/yyyy hh:mm:ss' format using Format() function VB.Net program to print date and time in 'day, month dd, yyyy' format using Format() function VB.Net program to print date and time in different formats using Format() function VB.Net program to print given number in different formats using Format() function VB.Net program to demonstrate the CBool() function VB.Net program to demonstrate the Val() function VB.Net program to demonstrate the GetChar() function VB.Net program to reverse the given number using the While loop VB.Net program to check the given number is palindrome or not using While loop VB.Net program to count the digits of given number using While loop VB.Net program to check given number is Armstrong or not using While loop VB.Net program to print the table of given number using Do While VB.Net program to print 1, 11, 31, 61, ... using Do While Loop VB.Net program to Enter a name and print 5 times using Do While Loop VB.Net program to demonstrate the boxing VB.Net program to demonstrate the un-boxing VB.Net program to create a constant using const keyword VB.Net program to print the name of Enum constants VB.Net program to print the default values of Enum constants VB.Net program to print explicitly initialized values of Enum VB.Net program to create a global variable VB.Net program to create a simple class and object VB.Net program to create multiple objects of the class VB.Net program to create an array of objects of the class VB.Net program to create an empty class VB.Net program to demonstrate the Mid() function VB.Net program to demonstrate the Trim() function VB.Net program to demonstrate the LTrim() function VB.Net program to demonstrate the RTrim() function