Net-informations.com
SiteMap  | About    

How to VB.NET String.Chars()

The VB.NET String Chars method return the character at the specified index of an instance

System.String.Chars(ByVal index As Integer) As Char

Parameters:

Integer index - The character position in the returned Character.

Returns:

Char - The return Character.

For ex :

"Return test".Chars(3) return a single character 'u'

If u pass a number more than String length will return an exception

"Return test".Chars(25) will throw a System.IndexOutOfRangeException

Exceptions:

System.IndexOutOfRangeException : The index is less than zero or greater than the length of String Object




Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        Dim str As String = "Returned Character Chars()"
        Dim singleChar As Char
        singleChar = str.Chars(3)
        MsgBox(singleChar)
    End Sub
End Class

When you run this source code you will return a messagebox show 'u'


 VB.NET String - Related Contents


 VB.NET String - Related Programs