Partager via


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

Exception type Error number Condition

ArgumentException

5

str is Nothing, Index < 1, or Index is greater than index of last character of str.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

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 TestString As String = "ABCDE"
Dim TestChar As Char
' Returns "D"
TestChar = GetChar(TestString, 4)

Requirements

Namespace: Microsoft.VisualBasic

Module: Strings

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

See Also

Reference

String Manipulation Summary
Mid Function (Visual Basic)
ArgumentException