Strings.Left(String, Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳包含指定字元數量的字串,來自字串左側。
public:
static System::String ^ Left(System::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。