Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

GetChar Function

Returns a Char value representing the character from the specified index in the supplied string.

Public Shared Function GetChar( _
   ByVal Str As String, _
   ByVal Index As Integer _
) As Char

Parameters

Str
Required. Any valid String expression.
Index
Required. Integer expression. The (1-based) index of the character in Str to be returned.

Exceptions/Errors

Exception type Error number Condition
ArgumentException 5 Str is Nothing, Index < 1, or Index is greater than index of last character of Str.

Remarks

If Index is less than 1 or greater than the index of the last character in Str, an ArgumentException is thrown.

Example

This example shows how to use the GetChar function to return a character from a specified index in a String.

Dim myString As String = "ABCDE"
Dim myChar As Char
myChar = GetChar(myString, 4)   ' myChar = "D"

Requirements

Namespace: Microsoft.VisualBasic

Module: Strings

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

Mid Function | ArgumentException Class

Show:
© 2015 Microsoft