Strings.Left(String, Int32) Metoda

Definice

Vrátí řetězec obsahující zadaný počet znaků od levé strany řetězce.Returns a string containing a specified number of characters from the left side of a string.

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

Parametry

str
String

Povinná hodnota.Required. String výraz, ze kterého jsou vráceny znaky nejvíce vlevoString expression from which the leftmost characters are returned.

Length
Int32

Povinná hodnota.Required. Integer vyjádření.Integer expression. Číselný výraz označující, kolik znaků se má vrátit.Numeric expression indicating how many characters to return. Pokud je nastaveno na hodnotu 0, je vrácen řetězec s nulovou délkou ("").If 0, a zero-length string ("") is returned. Pokud je větší nebo rovno počtu znaků v str , vrátí se celý řetězec.If greater than or equal to the number of characters in str, the entire string is returned.

Návraty

String

Řetězec obsahující zadaný počet znaků od levé strany řetězce.A string containing a specified number of characters from the left side of a string.

Výjimky

Length<0.Length < 0.

Příklady

Tento příklad ukazuje použití Left funkce k vrácení podřetězce daného String .This example demonstrates the use of the Left function to return a substring of a given String. Ve třídě, která má Left vlastnost, může být nutné plně kvalifikovat Left funkci.In a class that has a Left property, it may be necessary to fully qualify the Left function.

Dim testString As String = "Hello World!"
' Returns "Hello".
Dim subString As String = Left(testString, 5)

Poznámky

Chcete-li určit počet znaků v str , použijte Len funkci.To determine the number of characters in str, use the Len function. Je-li použit v aplikaci model Windows Forms nebo jakékoli jiné třídě, která má Left vlastnost, je nutné plně kvalifikovat funkci pomocí Microsoft.VisualBasic.Left .If used in a Windows Forms application, or any other class that has a Left property, you must fully qualify the function with Microsoft.VisualBasic.Left.

Poznámka

LeftBFunkce v předchozích verzích Visual Basic vrátí řetězec v bajtech namísto znaků.The LeftB function in previous versions of Visual Basic returns a string in bytes rather than characters. Používá se především pro převod řetězců v aplikacích dvoubajtové znakové sady (DBCS).It is used primarily for converting strings in double-byte character set (DBCS) applications. Všechny aktuální Visual Basic řetězce jsou v kódování Unicode a LeftB již nejsou podporovány.All current Visual Basic strings are in Unicode, and LeftB is no longer supported.

Platí pro

Viz také