ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the GetChar() function

Here, we are going to demonstrate the GetChar() function in VB.Net.
Submitted by Nidhi, on December 06, 2020

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

Syntax:

GetChar(str,index)

Parameters:

  • 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.

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.