×

VB.Net Programs

VB.Net program to demonstrate the Mid() function

By Nidhi Last Updated : November 13, 2024

Mid() function in VB.Net

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

Syntax

Mid(str, pos, n)

Parameter(s)

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

Return Value

The Mid() function will return a substring value.

VB.Net code to demonstrate the example of Mid() function

The source code to demonstrate the Mid() function is given below. The given program is compiled and executed successfully.

'VB.Net program to demonstrate the Mid() function.

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
Press any key to continue . . .

Explanation:

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

str2 = Mid(str1, 3, 4)

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

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.