Strings.Replace(String, String, String, Int32, Int32, CompareMethod) Metoda

Definice

Vrátí řetězec, ve kterém byl zadaný dílčí řetězec nahrazen jiným dílčím řetězcem, který je určený počtem opakování.Returns a string in which a specified substring has been replaced with another substring a specified number of times.

public static string? Replace (string? Expression, string? Find, string? Replacement, int Start = 1, int Count = -1, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
public static string Replace (string Expression, string Find, string Replacement, int Start = 1, int Count = -1, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
static member Replace : string * string * string * int * int * Microsoft.VisualBasic.CompareMethod -> string
Public Function Replace (Expression As String, Find As String, Replacement As String, Optional Start As Integer = 1, Optional Count As Integer = -1, Optional Compare As CompareMethod = Microsoft.VisualBasic.CompareMethod.Binary) As String

Parametry

Expression
String

Povinná hodnota.Required. Řetězcový výraz obsahující dílčí řetězec, který má být nahrazen.String expression containing substring to replace.

Find
String

Povinná hodnota.Required. Dílčí řetězec, který hledáte.Substring being searched for.

Replacement
String

Povinná hodnota.Required. Náhradní podřetězec.Replacement substring.

Start
Int32

Nepovinný parametr.Optional. Pozice v rámci Expression začíná podřetězecem použitým k nahrazení.Position within Expression that starts a substring used for replacement. Návratová hodnota Replace je řetězec, který začíná na Start s vhodnými náhradami.The return value of Replace is a string that begins at Start, with appropriate substitutions. Je-li tento parametr vynechán, předpokládá se hodnota 1.If omitted, 1 is assumed.

Count
Int32

Nepovinný parametr.Optional. Počet náhrad podřetězců, které mají být provedeny.Number of substring substitutions to perform. Je-li tento parametr vynechán, je použita výchozí hodnota-1, což znamená "udělat všechny možné náhrady".If omitted, the default value is -1, which means "make all possible substitutions."

Compare
CompareMethod

Nepovinný parametr.Optional. Číselná hodnota označující druh porovnání, které se má použít při vyhodnocování podřetězců.Numeric value indicating the kind of comparison to use when evaluating substrings. Viz nastavení pro hodnoty.See Settings for values.

Návraty

String

Jedna z následujících hodnot.One of the following values.

Pokud uživatelIfNahradit vratkyReplace returns
Find má nulovou délku nebo NothingFind is zero-length or Nothing Kopie ExpressionCopy of Expression
Replace je nulová délkaReplace is zero-length Kopie Expression bez výskytů FindCopy of Expression with no occurrences of Find
Expression má nulovou délku nebo Nothing Start je větší než délka ExpressionExpression is zero-length or Nothing, or Start is greater than length of ExpressionNothing
Count je 0Count is 0 Kopie ExpressionCopy of Expression

Výjimky

Count<-1 nebo Start < = 0.Count < -1 or Start <= 0.

Příklady

Tento příklad ukazuje Replace funkci.This example demonstrates the Replace function.

Dim TestString As String = "Shopping List"  
' Returns "Shipping List".  
Dim aString As String = Replace(TestString, "o", "i")  

Poznámky

Návratová hodnota Replace funkce je řetězec, který začíná na pozici určené hodnotou Start a končí na konci Expression řetězce, s náhradami provedenými podle Find Replace hodnot a.The return value of the Replace function is a string that begins at the position specified by Start and concludes at the end of the Expression string, with the substitutions made as specified by the Find and Replace values.

CompareArgument může obsahovat následující hodnoty.The Compare argument can have the following values.

KonstantaConstant DescriptionDescription
Binary Provádí binární porovnání.Performs a binary comparison
Text Provádí textové porovnání.Performs a textual comparison

Platí pro

Viz také