Strings.Replace(String, String, String, Int32, Int32, CompareMethod) Yöntem

Tanım

Belirtilen bir alt dizenin belirtilen sayıda başka bir alt dizeyle değiştirildiği bir dize döndürür.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

Parametreler

Expression
String

Gereklidir.Required. Değiştirilecek alt dizeyi içeren dize ifadesi.String expression containing substring to replace.

Find
String

Gereklidir.Required. Aranan alt dize.Substring being searched for.

Replacement
String

Gereklidir.Required. Değiştirme alt dizesi.Replacement substring.

Start
Int32

İsteğe bağlı.Optional. İçindeki konum Expression , değiştirme için kullanılan bir alt dizeyi başlatır.Position within Expression that starts a substring used for replacement. Dönüş değeri Replace Start , uygun değiştirmeler ile başlayan bir dizedir.The return value of Replace is a string that begins at Start, with appropriate substitutions. Atlanırsa, 1 varsayılır.If omitted, 1 is assumed.

Count
Int32

İsteğe bağlı.Optional. Gerçekleştirilecek alt dize değişimi sayısı.Number of substring substitutions to perform. Atlanırsa, varsayılan değer-1 ' dir ve bu, "tüm olası alternatifleri yap" anlamına gelir.If omitted, the default value is -1, which means "make all possible substitutions."

Compare
CompareMethod

İsteğe bağlı.Optional. Alt dizeleri değerlendirirken kullanılacak karşılaştırma türünü gösteren sayısal değer.Numeric value indicating the kind of comparison to use when evaluating substrings. Değerler için bkz. ayarlar.See Settings for values.

Döndürülenler

String

Aşağıdaki değerlerden biri.One of the following values.

EğerIfReplace dönüşlerReplace returns
Find sıfır uzunlukta veya NothingFind is zero-length or Nothing Kopyası ExpressionCopy of Expression
Replace sıfır uzunluktadırReplace is zero-length ExpressionOluşumu olmadan kopyasıFindCopy of Expression with no occurrences of Find
Expression sıfır uzunlukta veya Nothing veya Start uzunluğundan büyük ExpressionExpression is zero-length or Nothing, or Start is greater than length of ExpressionNothing
Count 0 ' dırCount is 0 Kopyası ExpressionCopy of Expression

Özel durumlar

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

Örnekler

Bu örnek, Replace işlevini gösterir.This example demonstrates the Replace function.

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

Açıklamalar

İşlevin dönüş değeri, Replace Start Expression ve değerleri tarafından belirtilen değiştirmeler ile, tarafından belirtilen konumda başlayan ve dizenin sonunda sona eriyor olan bir dizedir Find Replace .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.

CompareBağımsız değişkeni aşağıdaki değerlere sahip olabilir.The Compare argument can have the following values.

SabitConstant DescriptionDescription
Binary İkili karşılaştırma yaparPerforms a binary comparison
Text Metinsel karşılaştırma yaparPerforms a textual comparison

Şunlara uygulanır

Ayrıca bkz.