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最后一个字符的索引, ArgumentException 则会引发 。