共用方式為


Strings.GetChar 方法

傳回 Char 值,表示提供的字串內指定之索引的字元。

命名空間: Microsoft.VisualBasic
組件: Microsoft.VisualBasic (在 microsoft.visualbasic.dll 中)

語法

'宣告
Public Shared Function GetChar ( _
    str As String, _
    Index As Integer _
) As Char
'用途
Dim str As String
Dim Index As Integer
Dim returnValue As Char

returnValue = Strings.GetChar(str, Index)
public static char GetChar (
    string str,
    int Index
)
public:
static wchar_t GetChar (
    String^ str, 
    int Index
)
public static char GetChar (
    String str, 
    int Index
)
public static function GetChar (
    str : String, 
    Index : int
) : char

參數

  • str
    必要項。任何有效的 String 運算式。
  • Index
    必要項。Integer 運算式。所要傳回之 str 中的字元 (以 1 起始) 索引。

傳回值

傳回 Char 值,表示提供的字串內指定之索引的字元。

備註

如需詳細資訊,請參閱 Visual Basic 的主題 GetChar 函式

如果 Index 小於 1 或大於 str 中最後一個字元的索引,則會擲回 ArgumentException

範例

此範例將示範如何使用 GetChar 函式,從 String 內的指定之索引傳回字元。

Dim TestString As String = "ABCDE"
Dim TestChar As Char
' Returns "D"
TestChar = GetChar(TestString, 4)

平台

Windows 98、 Windows 2000 SP4、 Windows CE、 Windows Millennium Edition、 Windows Mobile for Pocket PC、 Windows Mobile for Smartphone、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition

.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。

版本資訊

.NET Framework

支援版本:2.0、1.1、1.0

.NET Compact Framework

支援版本:2.0、1.0

請參閱

參考

Strings 類別
Strings 成員
Microsoft.VisualBasic 命名空間
ArgumentException

其他資源

GetChar 函式
字串操作摘要
Mid 函式 (Visual Basic)