Strings.Left(String, Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回字串,其中包含從字串的左邊開始的指定數目的字元。
public:
static System::String ^ Left(System::String ^ str, int Length);
public static string Left (string? str, int Length);
public static string Left (string str, int Length);
static member Left : string * int -> string
Public Function Left (str As String, Length As Integer) As String
參數
- str
- String
必要。 String
運算式,最左邊的字元會從此運算式中傳回。
- Length
- Int32
必要。 Integer
運算式。 數值運算式,表示要傳回的字元數。 如果為 0,則會傳回長度為零的字串 ("")。 如果大於或等於 str
中的字元數,則會傳回整個字串。
傳回
字串,其中包含從字串的左邊開始的指定數目的字元。
例外狀況
Length
< 0.
範例
此範例示範如何使用 Left
函式傳回指定 String
的子字串。 在具有 屬性的 Left
類別中,可能需要完整限定函 Left
式。
Dim testString As String = "Hello World!"
' Returns "Hello".
Dim subString As String = Left(testString, 5)
備註
若要判斷 中的 str
字元數,請使用 函 Len
式。 如果在 Windows Forms 應用程式中使用,或任何其他具有 屬性的Left
類別,您必須使用 完整限定函Microsoft.VisualBasic.Left
式。
注意
舊版 Visual Basic 中的函 LeftB
式會以位元組而非字元傳回字串。 其主要用於在雙位元組字元集 (DBCS) 應用程式中轉換字串。 所有目前的 Visual Basic 字串都位於 Unicode 中,不再 LeftB
支援。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應