Strings.GetChar(String, Int32) 方法

定义

返回一个 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 表示所提供字符串中指定索引中的字符的值。

例外

strNothingIndex< 1 或 Index 大于最后一个字符的 str索引。

示例

此示例演示如何使用 GetChar 函数从指定索引中 String返回字符。

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

注解

如果 Index 小于 1 或大于最后 str一个字符的索引,则会引发一个 ArgumentException

适用于

另请参阅