Share via


Strings.GetChar(String, Int32) Metodo

Definizione

Restituisce un valore Char che rappresenta il carattere dell'indice specificato nella stringa fornita.

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

Parametri

str
String

Obbligatorio. Qualsiasi espressione String valida.

Index
Int32

Obbligatorio. Espressione Integer. L'indice (in base 1) del carattere di str da restituire.

Restituisce

Valore Char che rappresenta il carattere dell'indice specificato nella stringa fornita.

Eccezioni

str è Nothing, Index< 1 o Index è maggiore dell'indice dell'ultimo carattere di str.

Esempio

In questo esempio viene illustrato come usare la GetChar funzione per restituire un carattere da un indice specificato in un oggetto String.

Dim testString As String = "ABCDE"
Dim testChar As Char
' Returns "D"
testChar = GetChar(testString, 4)

Commenti

Se Index è minore di 1 o maggiore dell'indice dell'ultimo carattere in str, viene generata un'eccezione ArgumentException .

Si applica a

Vedi anche