MaskedTextProvider.Replace 方法

定义

用指定的字符替换带格式字符串中的一个或多个可编辑字符。Replaces one or more editable characters in the formatted string with the specified characters.

重载

Replace(String, Int32, Int32, Int32, MaskedTextResultHint)

在指定的开始位置和结束位置之间的范围内使用指定的字符串替换可编辑字符,然后输出移除位置和描述性信息。Replaces a range of editable characters between the specified starting and ending positions with the specified string, and then outputs the removal position and descriptive information.

Replace(Char, Int32, Int32, Int32, MaskedTextResultHint)

在指定的开始和结束位置之间使用指定的字符值替换单个字符,然后输出移除位置和描述性信息。Replaces a single character between the specified starting and ending positions with the specified character value, and then outputs the removal position and descriptive information.

Replace(String, Int32, Int32, MaskedTextResultHint)

从指定位置开始使用指定字符串替换一定范围的可编辑字符,然后输出移除位置和描述性信息。Replaces a range of editable characters starting at the specified position with the specified string, and then outputs the removal position and descriptive information.

Replace(Char, Int32, Int32, MaskedTextResultHint)

用指定的字符值替换指定位置或指定位置后面的单个字符,然后输出移除位置和描述性信息。Replaces a single character at or beyond the specified position with the specified character value, and then outputs the removal position and descriptive information.

Replace(String, Int32)

从指定位置开始使用指定字符串替换一定范围的可编辑字符。Replaces a range of editable characters starting at the specified position with the specified string.

Replace(Char, Int32)

用指定的字符值替换指定位置或指定位置后面的单个字符。Replaces a single character at or beyond the specified position with the specified character value.

Replace(String, Int32, Int32, Int32, MaskedTextResultHint)

在指定的开始位置和结束位置之间的范围内使用指定的字符串替换可编辑字符,然后输出移除位置和描述性信息。Replaces a range of editable characters between the specified starting and ending positions with the specified string, and then outputs the removal position and descriptive information.

public:
 bool Replace(System::String ^ input, int startPosition, int endPosition, [Runtime::InteropServices::Out] int % testPosition, [Runtime::InteropServices::Out] System::ComponentModel::MaskedTextResultHint % resultHint);
public bool Replace (string input, int startPosition, int endPosition, out int testPosition, out System.ComponentModel.MaskedTextResultHint resultHint);
member this.Replace : string * int * int * int * MaskedTextResultHint -> bool
Public Function Replace (input As String, startPosition As Integer, endPosition As Integer, ByRef testPosition As Integer, ByRef resultHint As MaskedTextResultHint) As Boolean

参数

input
String

用于替换现有可编辑字符的 String 值。The String value used to replace the existing editable characters.

startPosition
Int32

带格式的字符串中的替换起始位置(从零开始计)。The zero-based position in the formatted string where the replacement starts.

endPosition
Int32

带格式的字符串中的替换结束位置(从零开始计)。The zero-based position in the formatted string where the replacement ends.

testPosition
Int32

如果成功,则为带格式字符串中实际替换最后一个字符的位置(从零开始计);否则为该操作第一次失败时所处的位置。If successful, the zero-based position in the formatted string where the last character was actually replaced; otherwise, the first position where the operation failed. 一个输出参数。An output parameter.

resultHint
MaskedTextResultHint

一个 MaskedTextResultHint,用于简单地描述替换操作的结果。A MaskedTextResultHint that succinctly describes the result of the replacement operation. 一个输出参数。An output parameter.

返回

Boolean

如果所有的字符已成功替换,则为 true;否则为 falsetrue if all the characters were successfully replaced; otherwise, false.

注解

Replace方法在指定的起始位置和结束位置之间搜索带格式字符串中的第一个可编辑位置。The Replace method searches for the first editable position in the formatted string between the specified starting and ending positions. 假设在此点之后有足够的可编辑位置,现有字符值将逐个替换为替换字符串参数的内容 inputOperating on the assumption that there are enough editable positions after this point, the existing character values are replaced one-by-one with the contents of the replacement string parameter, input.

以下情况被视为错误。The following conditions are considered errors. 出现错误时,不会发生任何替换并 Replace 返回 falseWhen an error occurs, no replacement occurs and Replace returns false.

  • startPosendPos 参数指向带格式字符串的开头或超出其结尾的位置。The startPos or endPos parameters point before the start of the formatted string or beyond its end.

  • 带格式字符串中的可编辑位置不足,无法保存替换字符串的内容。There are not enough editable positions in the formatted string to hold the contents of the replacement string.

  • 其中一个替换字符值无效,因为它不可打印或与其相应的掩码元素不匹配。One of the replacement character values is not valid because it is not printable or does not match its corresponding mask element.

除了返回值,此方法还提供两个输出参数以提供有关替换操作的其他信息。In addition to the return value, this method has two output parameters to supply additional information about the replacement operation.

另请参阅

适用于

Replace(Char, Int32, Int32, Int32, MaskedTextResultHint)

在指定的开始和结束位置之间使用指定的字符值替换单个字符,然后输出移除位置和描述性信息。Replaces a single character between the specified starting and ending positions with the specified character value, and then outputs the removal position and descriptive information.

public:
 bool Replace(char input, int startPosition, int endPosition, [Runtime::InteropServices::Out] int % testPosition, [Runtime::InteropServices::Out] System::ComponentModel::MaskedTextResultHint % resultHint);
public bool Replace (char input, int startPosition, int endPosition, out int testPosition, out System.ComponentModel.MaskedTextResultHint resultHint);
member this.Replace : char * int * int * int * MaskedTextResultHint -> bool
Public Function Replace (input As Char, startPosition As Integer, endPosition As Integer, ByRef testPosition As Integer, ByRef resultHint As MaskedTextResultHint) As Boolean

参数

input
Char

用于替换现有值的 Char 值。The Char value that replaces the existing value.

startPosition
Int32

带格式的字符串中的替换起始位置(从零开始计)。The zero-based position in the formatted string where the replacement starts.

endPosition
Int32

带格式的字符串中的替换结束位置(从零开始计)。The zero-based position in the formatted string where the replacement ends.

testPosition
Int32

如果成功,则为带格式字符串中实际替换最后一个字符的位置(从零开始计);否则为该操作第一次失败时所处的位置。If successful, the zero-based position in the formatted string where the last character was actually replaced; otherwise, the first position where the operation failed. 一个输出参数。An output parameter.

resultHint
MaskedTextResultHint

一个 MaskedTextResultHint,用于简单地描述替换操作的结果。A MaskedTextResultHint that succinctly describes the result of the replacement operation. 一个输出参数。An output parameter.

返回

Boolean

如果已成功替换该字符,则为 true;否则为 falsetrue if the character was successfully replaced; otherwise, false.

注解

Replace(Char, Int32, Int32, Int32, MaskedTextResultHint)方法在指定的起始位置和结束位置之间搜索带格式字符串中的第一个可编辑位置。The Replace(Char, Int32, Int32, Int32, MaskedTextResultHint) method searches for the first editable position in the formatted string between the specified starting and ending positions. 如果找到一个,则可编辑位置的值将更改为指定的字符 inputIf one is found, the value of the editable position is changed to the specified character, input. 以下任何条件都将导致错误条件,导致不执行替换,并返回的值 falseAny of the following conditions will result in an error condition that causes no replacement to be performed and a value of false to be returned:

  • startPosendPos 参数指向带格式字符串的开头或超出其结尾的位置。The startPos or endPos parameters point before the start of the formatted string or beyond its end.

  • 在指定的时间间隔内找不到可编辑字符。An editable character was not found in the specified interval.

  • 替换字符不是 input 有效的输入字符,因为它不可打印或与其相应的掩码元素不匹配。The replacement character, input, is not a valid input character because it is not printable or does not match its corresponding mask element.

除了返回值,此方法还提供两个输出参数以提供有关替换操作的其他信息。In addition to the return value, this method has two output parameters to supply additional information about the replacement operation.

另请参阅

适用于

Replace(String, Int32, Int32, MaskedTextResultHint)

从指定位置开始使用指定字符串替换一定范围的可编辑字符,然后输出移除位置和描述性信息。Replaces a range of editable characters starting at the specified position with the specified string, and then outputs the removal position and descriptive information.

public:
 bool Replace(System::String ^ input, int position, [Runtime::InteropServices::Out] int % testPosition, [Runtime::InteropServices::Out] System::ComponentModel::MaskedTextResultHint % resultHint);
public bool Replace (string input, int position, out int testPosition, out System.ComponentModel.MaskedTextResultHint resultHint);
member this.Replace : string * int * int * MaskedTextResultHint -> bool
Public Function Replace (input As String, position As Integer, ByRef testPosition As Integer, ByRef resultHint As MaskedTextResultHint) As Boolean

参数

input
String

用于替换现有可编辑字符的 String 值。The String value used to replace the existing editable characters.

position
Int32

用于搜索将要替换的第一个可编辑字符的位置(从零开始计)。The zero-based position to search for the first editable character to replace.

testPosition
Int32

如果成功,则为带格式字符串中实际替换最后一个字符的位置(从零开始计);否则为该操作第一次失败时所处的位置。If successful, the zero-based position in the formatted string where the last character was actually replaced; otherwise, the first position where the operation failed. 一个输出参数。An output parameter.

resultHint
MaskedTextResultHint

一个 MaskedTextResultHint,用于简单地描述替换操作的结果。A MaskedTextResultHint that succinctly describes the result of the replacement operation. 一个输出参数。An output parameter.

返回

Boolean

如果所有的字符已成功替换,则为 true;否则为 falsetrue if all the characters were successfully replaced; otherwise, false.

注解

Replace(String, Int32, Int32, MaskedTextResultHint)方法搜索指定位置或指定位置之外的第一个可编辑位置 posThe Replace(String, Int32, Int32, MaskedTextResultHint) method searches for the first editable position at or beyond the specified position, pos. 假设在此点之后有足够的可编辑位置,现有字符值将逐个替换为替换字符串参数的内容 inputOperating on the assumption that there are enough editable positions after this point, the existing character values are replaced one-by-one with the contents of the replacement string parameter, input.

以下情况被视为错误。The following conditions are considered errors. 出现错误时,不会发生任何替换并 Replace(String, Int32, Int32, MaskedTextResultHint) 返回 falseWhen an error occurs, no replacement occurs and Replace(String, Int32, Int32, MaskedTextResultHint) returns false.

  • pos参数小于零或大于 Length 带格式字符串的。The pos parameter is less than zero or greater than the Length of the formatted string.

  • 带格式字符串中的可编辑位置不足,无法保存替换字符串的内容。There are not enough editable positions in the formatted string to hold the contents of the replacement string.

  • 其中一个替换字符值无效,因为它不可打印或与其相应的掩码元素不匹配。One of the replacement character values is not valid because it is not printable or does not match its corresponding mask element.

除了返回值,此方法还提供两个输出参数以提供有关替换操作的其他信息。In addition to the return value, this method has two output parameters to supply additional information about the replacement operation.

另请参阅

适用于

Replace(Char, Int32, Int32, MaskedTextResultHint)

用指定的字符值替换指定位置或指定位置后面的单个字符,然后输出移除位置和描述性信息。Replaces a single character at or beyond the specified position with the specified character value, and then outputs the removal position and descriptive information.

public:
 bool Replace(char input, int position, [Runtime::InteropServices::Out] int % testPosition, [Runtime::InteropServices::Out] System::ComponentModel::MaskedTextResultHint % resultHint);
public bool Replace (char input, int position, out int testPosition, out System.ComponentModel.MaskedTextResultHint resultHint);
member this.Replace : char * int * int * MaskedTextResultHint -> bool
Public Function Replace (input As Char, position As Integer, ByRef testPosition As Integer, ByRef resultHint As MaskedTextResultHint) As Boolean

参数

input
Char

用于替换现有值的 Char 值。The Char value that replaces the existing value.

position
Int32

用于搜索将要替换的第一个可编辑字符的位置(从零开始计)。The zero-based position to search for the first editable character to replace.

testPosition
Int32

如果成功,则为带格式字符串中实际替换最后一个字符的位置(从零开始计);否则为该操作第一次失败时所处的位置。If successful, the zero-based position in the formatted string where the last character was actually replaced; otherwise, the first position where the operation failed. 一个输出参数。An output parameter.

resultHint
MaskedTextResultHint

一个 MaskedTextResultHint,用于简单地描述替换操作的结果。A MaskedTextResultHint that succinctly describes the result of the replacement operation. 一个输出参数。An output parameter.

返回

Boolean

如果已成功替换该字符,则为 true;否则为 falsetrue if the character was successfully replaced; otherwise, false.

注解

Replace(Char, Int32, Int32, MaskedTextResultHint)方法在格式字符串中的指定位置或指定位置之外搜索第一个可编辑位置 posThe Replace(Char, Int32, Int32, MaskedTextResultHint) method searches for the first editable position in the formatted string at or beyond the specified position, pos. 如果找到一个,则可编辑位置的值将更改为指定的字符 inputIf one is found, the value of the editable position is changed to the specified character, input. 以下任何条件都将导致错误条件,导致不执行替换,并返回的值 falseAny of the following conditions will result in an error condition that causes no replacement to be performed and a value of false to be returned:

  • pos参数小于零或大于 Length 带格式字符串的。The pos parameter is less than zero or greater than the Length of the formatted string.

  • 在指定位置或指定位置之外的格式化字符串中找不到可编辑字符 posAn editable character was not found in the formatted string at or beyond the specified position, pos.

  • 替换字符不是 input 有效的输入字符,因为它不可打印或与其相应的掩码元素不匹配。The replacement character, input, is not a valid input character because it is not printable or does not match its corresponding mask element.

除了返回值,此方法还提供两个输出参数以提供有关替换操作的其他信息。In addition to the return value, this method has two output parameters to supply additional information about the replacement operation.

另请参阅

适用于

Replace(String, Int32)

从指定位置开始使用指定字符串替换一定范围的可编辑字符。Replaces a range of editable characters starting at the specified position with the specified string.

public:
 bool Replace(System::String ^ input, int position);
public bool Replace (string input, int position);
member this.Replace : string * int -> bool
Public Function Replace (input As String, position As Integer) As Boolean

参数

input
String

用于替换现有可编辑字符的 String 值。The String value used to replace the existing editable characters.

position
Int32

用于搜索将要替换的第一个可编辑字符的位置(从零开始计)。The zero-based position to search for the first editable character to replace.

返回

Boolean

如果所有的字符已成功替换,则为 true;否则为 falsetrue if all the characters were successfully replaced; otherwise, false.

例外

input 参数为 nullThe input parameter is null.

注解

Replace(String, Int32)方法搜索指定位置或指定位置之外的第一个可编辑位置 posThe Replace(String, Int32) method searches for the first editable position at or beyond the specified position, pos. 如果在此点之后有足够的可编辑位置进行操作,则会将现有字符值逐个替换为替换字符串参数的内容 inputOperating under the assumption that there are enough editable positions after this point, the existing character values are replaced one-by-one with the contents of the replacement string parameter, input.

以下情况被视为错误。The following conditions are considered errors. 出现错误时,不会发生任何替换并 Replace(String, Int32) 返回 falseWhen an error occurs, no replacement occurs and Replace(String, Int32) returns false.

  • pos参数小于零或大于 Length 带格式字符串的。The pos parameter is less than zero or greater than the Length of the formatted string.

  • 带格式字符串中的可编辑位置不足,无法保存替换字符串的内容。There are not enough editable positions in the formatted string to hold the contents of the replacement string.

  • 其中一个替换字符值无效,因为它不可打印或与其相应的掩码元素不匹配。One of the replacement character values is not valid because it is not printable or does not match its corresponding mask element.

另请参阅

适用于

Replace(Char, Int32)

用指定的字符值替换指定位置或指定位置后面的单个字符。Replaces a single character at or beyond the specified position with the specified character value.

public:
 bool Replace(char input, int position);
public bool Replace (char input, int position);
member this.Replace : char * int -> bool
Public Function Replace (input As Char, position As Integer) As Boolean

参数

input
Char

用于替换现有值的 Char 值。The Char value that replaces the existing value.

position
Int32

用于搜索将要替换的第一个可编辑字符的位置(从零开始计)。The zero-based position to search for the first editable character to replace.

返回

Boolean

如果已成功替换该字符,则为 true;否则为 falsetrue if the character was successfully replaced; otherwise, false.

注解

Replace(Char, Int32)方法在格式字符串中的指定位置或指定位置之外搜索第一个可编辑位置 posThe Replace(Char, Int32) method searches for the first editable position in the formatted string at or beyond the specified position, pos. 如果找到一个,则可编辑位置的值将更改为指定的字符 inputIf one is found, the value of the editable position is changed to the specified character, input. 以下任何条件都将导致错误,导致不执行任何替换,并返回的值 falseAny of the following conditions will result in an error that causes no replacement to be performed and a value of false to be returned:

  • pos参数小于零或大于 Length 带格式字符串的。The pos parameter is less than zero or greater than the Length of the formatted string.

  • 在指定位置或指定位置之外的格式化字符串中找不到可编辑字符 posAn editable character was not found in the formatted string at or beyond the specified position, pos.

  • 替换字符不是 input 有效的输入字符,因为它不可打印或与其相应的掩码元素不匹配。The replacement character, input, is not a valid input character because it is not printable or does not match its corresponding mask element.

另请参阅

适用于