Skip to content

Replace

Xusinboy Bekchanov edited this page Nov 6, 2023 · 9 revisions

Replace Function

Returns a string, which is a substring of a string expression beginning at the start position (defaults to 1), in which a specified substring has been replaced with another substring a specified number of times.

Syntax

Function Replace(ByRef Expression As WString, ByRef FindingText As WString, ByRef ReplacingText As WString, ByVal Start As Integer = 1, ByRef Count As Integer = 0, MatchCase As Boolean = True) As UString

Parameters

Part Type Description
Expression WString Required. String expression containing substring to replace.
FindingText WString Required. Substring being searched for.
ReplacingText WString Required. Replacement substring.
Start Integer Optional. Start position for the substring of Expression to be searched and returned. If omitted, 1 is assumed.
Count Integer Optional. Number of substring substitutions to perform. If omitted, the default value is -1, which means, make all possible substitutions.
MatchCase Boolean Optional. Boolean value indicating the kind of comparison to use when evaluating substrings.

Return Value

UString

Replace returns the following values:

If Replace returns
Expression is zero-length Zero-length string ("")
Expression is NULL An error.
FindingText is zero-length Copy of Expression.
ReplacingText is zero-length Copy of Expression with all occurrences of FindingText removed.
Start > Len(Expression) Zero-length string. String replacement begins at the position indicated by Start.
Count is 0 Copy of Expression.

Remarks

The Return value of the Replace function is a string, with substitutions made, that begins at the position specified by Start and concludes at the End of the Expression string. It's not a copy of the original string from start to finish.

Example

 #include "mff/UString.bi"

 Dim strFull As String = "My name is Adam"

 Print Replace(strFull, "Adam", "Victor")

 Sleep

See also

Clone this wiki locally