Share via


Strings.GetChar(String, Int32) Méthode

Définition

Retourne une valeur Char qui représente le caractère de l'index spécifié dans la chaîne fournie.

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

Paramètres

str
String

Obligatoire. Toute expression String valide.

Index
Int32

Obligatoire. Expression Integer. Index (de base 1) du caractère de str à retourner.

Retours

Valeur Char qui représente le caractère de l'index spécifié dans la chaîne fournie.

Exceptions

str a la valeur Nothing, Index< 1 ou Index est supérieur à l’index du dernier caractère de str.

Exemples

Cet exemple montre comment utiliser la GetChar fonction pour renvoyer un caractère à partir d’un index spécifié dans un String.

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

Remarques

Si Index est inférieur à 1 ou supérieur à l’index du dernier caractère dans str, un ArgumentException est levée.

S’applique à

Voir aussi