Strings.GetChar(String, Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳 Char 一個代表字元的值,來自所提供字串中指定的索引。
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
參數
- str
- String
必須的。 任何有效的 String 表達方式。
- Index
- Int32
必須的。
Integer 表達式。 要回傳的字元 str 的(以 1 為基礎)索引。
傳回
Char 代表所提供字串中指定索引字元的值。
例外狀況
str 是 Nothing, Index< 1,或 Index 大於 的 str最後一個字元的指標。
範例
此範例展示了如何使用 GetChar 函式從指定索引 String中回傳字元。
Dim testString As String = "ABCDE"
Dim testChar As Char
' Returns "D"
testChar = GetChar(testString, 4)
備註
如果 Index 小於 1 或大於 中 str最後一個字元的索引,則會拋出 an ArgumentException 。