Strings.Mid Metoda

Definice

Vrátí řetězec, který obsahuje znaky ze zadaného řetězce.Returns a string that contains characters from a specified string.

Přetížení

Mid(String, Int32)

Vrátí řetězec, který obsahuje všechny znaky od zadané pozice v řetězci.Returns a string that contains all the characters starting from a specified position in a string.

Mid(String, Int32, Int32)

Vrátí řetězec, který obsahuje zadaný počet znaků od zadané pozice v řetězci.Returns a string that contains a specified number of characters starting from a specified position in a string.

Mid(String, Int32)

Vrátí řetězec, který obsahuje všechny znaky od zadané pozice v řetězci.Returns a string that contains all the characters starting from a specified position in a string.

public:
 static System::String ^ Mid(System::String ^ str, int Start);
public static string? Mid (string? str, int Start);
public static string Mid (string str, int Start);
static member Mid : string * int -> string
Public Function Mid (str As String, Start As Integer) As String

Parametry

str
String

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

Start
Int32

Povinná hodnota.Required. Integer vyjádření.Integer expression. Počáteční pozice znaků, které se mají vrátit.Starting position of the characters to return. Pokud Start je větší než počet znaků v str , Mid funkce vrátí řetězec s nulovou délkou ("").If Start is greater than the number of characters in str, the Mid function returns a zero-length string (""). Start je založen na jednom.Start is one-based.

Návraty

String

Řetězec, který se skládá ze všech znaků od zadané pozice v řetězci.A string that consists of all the characters starting from the specified position in the string.

Výjimky

Start<= 0 nebo Length < 0,8.Start <= 0 or Length < 0.

Příklady

Poslední řádek v tomto příkladu používá toto přetížení Mid funkce k vrácení pátého a následného znaku z řetězce.The last line in this example uses this overload of the Mid function to return the fifth and subsequent characters from a string.

' 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)

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.

Visual Basic má Mid funkci a Mid příkaz.Visual Basic has a Mid function and a Mid statement. Tyto prvky jsou provozovány na zadaném počtu znaků v řetězci, ale Mid funkce vrátí znaky, zatímco Mid příkaz nahradí znaky.These elements both operate on a specified number of characters in a string, but the Mid function returns the characters while the Mid statement replaces the characters. Další informace naleznete v tématu příkaz Mid.For more information, see Mid Statement.

Poznámka

MidBFunkce v předchozích verzích Visual Basic vrátí řetězec v bajtech namísto znaků.The MidB 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 Visual Basic řetězce jsou v kódování Unicode a MidB již nejsou podporovány.All Visual Basic strings are in Unicode, and MidB is no longer supported.

Viz také

Platí pro

Mid(String, Int32, Int32)

Vrátí řetězec, který obsahuje zadaný počet znaků od zadané pozice v řetězci.Returns a string that contains a specified number of characters starting from a specified position in a string.

public:
 static System::String ^ Mid(System::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);
static member Mid : string * int * int -> string
Public Function Mid (str As String, Start As Integer, Length As Integer) As String

Parametry

str
String

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

Start
Int32

Povinná hodnota.Required. Integer vyjádření.Integer expression. Počáteční pozice znaků, které se mají vrátit.Starting position of the characters to return. Pokud Start je větší než počet znaků v str , Mid funkce vrátí řetězec s nulovou délkou ("").If Start is greater than the number of characters in str, the Mid function returns a zero-length string (""). Start je jedna založená na.Start is one based.

Length
Int32

Nepovinný parametr.Optional. Integer vyjádření.Integer expression. Počet znaků, které mají být vráceny.Number of characters to return. Pokud je vynecháno nebo pokud je Length v textu méně než znaků (včetně znaku na pozici Start ), jsou vráceny všechny znaky z počáteční pozice na konec řetězce.If omitted or if there are fewer than Length characters in the text (including the character at position Start), all characters from the start position to the end of the string are returned.

Návraty

String

Řetězec, který se skládá ze zadaného počtu znaků od zadané pozice v řetězci.A string that consists of the specified number of characters starting from the specified position in the string.

Výjimky

Start<= 0 nebo Length < 0,8.Start <= 0 or Length < 0.

Příklady

První dvě Mid funkce v tomto příkladu vrátí zadaný počet znaků z řetězce od zadaných pozic.The first two Mid functions in this example return the specified number of characters from a string, starting from the given positions. (Poslední funkce ilustruje Mid(String, Int32) přetížení a určuje pouze počáteční bod pro extrakci řetězců.)(The last function illustrates the Mid(String, Int32) overload and only specifies the starting point for the string extraction.)

' 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)

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.

Visual Basic má Mid funkci a Mid příkaz.Visual Basic has a Mid function and a Mid statement. Tyto prvky jsou provozovány na zadaném počtu znaků v řetězci, ale Mid funkce vrátí znaky, zatímco Mid příkaz nahradí znaky.These elements both operate on a specified number of characters in a string, but the Mid function returns the characters while the Mid statement replaces the characters. Další informace naleznete v tématu příkaz Mid.For more information, see Mid Statement.

Poznámka

MidBFunkce v předchozích verzích Visual Basic vrátí řetězec v bajtech namísto znaků.The MidB 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 Visual Basic řetězce jsou v kódování Unicode a MidB již nejsou podporovány.All Visual Basic strings are in Unicode, and MidB is no longer supported.

Viz také

Platí pro