×

VB.Net Programs

VB.Net program to demonstrate the GetChar() function

By Nidhi Last Updated : November 11, 2024

GetChar() function in VB.Net

The GetChar() function is used to get the character from the string on a specified index.

Syntax

GetChar(str,index)

Parameter(s)

  • str: It is a specified string.
  • index: It is an index to get the character from the string.

Return Value

The Val() function will return the character from the string on the specified index.

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

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

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

Module Module1

    Sub Main()
        Dim ch As Char
        Dim str1 As String = "Hello World"
        Dim str2 As String = "Hello India"
        Dim str3 As String = "Hello Delhi"

        ch = GetChar(str1, 5)
        Console.WriteLine("Char at index {0}: {1}", 5, ch)

        ch = GetChar(str2, 7)
        Console.WriteLine("Char at index {0}: {1}", 7, ch)

        ch = GetChar(str3, 8)
        Console.WriteLine("Char at index {0}: {1}", 8, ch)
    End Sub

End Module

Output:

Char at index 5: o
Char at index 7: I
Char at index 8: e
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 three variables str1, str2, and str3 that are initialized with "Hello World", "Hello India", and "Hello Delhi".

ch = GetChar(str1, 5)
Console.WriteLine("Char at index {0}: {1}", 5, ch)

ch = GetChar(str2, 7)
Console.WriteLine("Char at index {0}: {1}", 7, ch)

ch = GetChar(str3, 8)
Console.WriteLine("Char at index {0}: {1}", 8, ch)

In the above code, we got the character from a specified string on a specified index and then we printed them on the console screen.

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





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