Edit

Share via


Strings.GetChar(String, Int32) Method

Definition

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

public:
 static char GetChar(System::String ^ str, int Index);
public static char GetChar (string str, int Index);
static member GetChar : string * int -> char
Public Function GetChar (str As String, Index As Integer) As Char

Parameters

str
String

Required. Any valid String expression.

Index
Int32

Required. Integer expression. The (1-based) index of the character in str to be returned.

Returns

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

Exceptions

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

Examples

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)

Remarks

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

Applies to

See also