傳回包含來自於某一字串之指定字元數量的字串。
命名空間: Microsoft.VisualBasic
組件: Microsoft.VisualBasic (在 microsoft.visualbasic.dll 中)
語法
'宣告
Public Shared Function Mid ( _
str As String, _
Start As Integer, _
Length As Integer _
) As String
'用途
Dim str As String
Dim Start As Integer
Dim Length As Integer
Dim returnValue As String
returnValue = Strings.Mid(str, Start, Length)
public static string Mid (
string str,
int Start,
int Length
)
public:
static String^ Mid (
String^ str,
int Start,
int Length
)
public static String Mid (
String str,
int Start,
int Length
)
public static function Mid (
str : String,
Start : int,
Length : int
) : String
參數
- str
必要項。String 運算式,字元會從此運算式中傳回。
- Start
必要項。Integer 運算式。要傳回字元的開始位置。如果 Start 大於 str 中的字元數,則 Mid 函式會傳回長度為零的字串 ("");Start 是以 1 起始的。
- Length
選擇項。Integer 運算式。要傳回的字元數。如果省略,或者此字元數少於文字中的 Length 字元 (包括 Start 位置上的字元),則會傳回從起始位置到字串結尾的所有字元。
傳回值
傳回包含來自於某一字串之指定字元數量的字串。
備註
如需詳細資訊,請參閱 Visual Basic 的主題 Mid 函式 (Visual Basic)。
若要判斷 str 中的字元數,請使用 Len 函式。
Visual Basic 具有 Mid 函式及 Mid 陳述式。這些項目都會在字串內指定數目的字元上運作,但是 Mid 函式會傳回字元,而 Mid 陳述式則是會取代字元。如需詳細資訊,請參閱 Mid 陳述式。
注意事項 |
|---|
舊版 Visual Basic 中的 MidB 函式會傳回位元組中的字串,而非字元。這項功能主要用來轉換雙位元組字元集 (DBCS) 應用程式中的字串。所有的 Visual Basic 字串都是以 Unicode 編碼,且不再支援 MidB。 |
範例
此範例使用 Mid 函式,從字串中傳回指定數目的字元。
' Creates text string.
Dim TestString As String = "Mid Function Demo"
' Returns "Mid".
Dim FirstWord As String = Mid(TestString, 1, 3)
' Returns "Demo".
Dim LastWord As String = Mid(TestString, 14, 4)
' Returns "Function Demo".
Dim MidWords As String = Mid(TestString, 5)
平台
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
其他資源
Mid 函式 (Visual Basic)
字串操作摘要
Visual Basic 中的字串
Visual Basic 中的字串簡介
Left 函式 (Visual Basic)
Len 函式 (Visual Basic)
Trim、LTrim 及 RTrim 函式
Mid 陳述式
Right 函式 (Visual Basic)
程式設計項目的支援變更摘要
注意事項