Replace Procedure

Version 7

 

Returns a string in which a specified substring, sFind, has been replaced with another substring, sReplacewith, a specified number of times, lCount.

Syntax

[ sStr = ] Replace ( sInStr, sFind, sReplaceWith, [lStart], [lCount], [bCompareNoCase] )

The Replace procedure syntax has the following parts:

Name

Type

Description

sStr

BString

Return String : after find and replace a number of times, lCount

sInStr

Val BString

String expression containing substring to replace.

sFind

Val BString

Substring being searched for.

sReplaceWith

Val BString

Replacement substring.

lStart

[Val] Long

Position within input string where substring search is to begin. Default value is 0 for start from beginning of sInStr.

lCount

[Val] Long

Number of substring replacements to perform. If omitted, the default value is -1, which means make all possible replacements.

bCompareNoCase

[Val] Bool

True (default) means no-case comparison, and False means case comparison.

Comments

The following shows what Replace returns on some cases:

If

Replace returns

Input String is of zero-length

zero-length string

'find' string is of zero-length

a copy of input string

'replacewith' string is of zero-length

a copy of input string with all occurrences of 'find' string removed

lStart > Length(InputString)

zero-length string

lCount is 0

a copy of input string

Example

The following example replaces every occurrences new line characters to a space:

print Replace(sIn, "\r\n", " ")

No-case (and Case) comparison starting at the beginning of the string.

Replace("XXpXXPXXp", "p", "Y") ! returns XXYXXYXXY

Replace("XXpXXPXXp", "p", "Y",,,FALSE) ! returns XXYXXPXXY

See Also

Filter, Join, Split