VBScript Replace
Function
The Replace
function replaces a specified part of a string with another string a specified number of times.
Syntax
Parameter | Description |
---|---|
string | Required. The string to be searched. |
find | Required. The part of the string to be replaced. |
replacewith | Required. The substring to replace with. |
start | Optional. The specified starting position. The default value is 1. All characters before the starting position will be removed. |
count | Optional. Specifies the number of replacements to perform. <br>The default value is -1, indicating all possible replacements. |
compare | Optional. Specifies the type of string comparison to use. The default is 0. Possible values are: 0 = vbBinaryCompare - Perform binary comparison<br> 1 = vbTextCompare - Perform text comparison |
Example
Example 1
Replace the word "beautiful" with "fantastic":
The output of the above example:
Example 2
Replace the letter "i" with "##":
The output of the above example:
Example 3
Replace the letter "i" with "##", starting from position 15:
Note that all characters before position 15 will be removed.
The output of the above example:
Example 4
Replace the first 2 occurrences of the letter "i" with "##", starting from position 1:
The output of the above example:
Example 5
Replace the letter "t" with "##", using text and binary comparison:
The output of the above example: