VBScript Replace Function
Complete VBScript Reference Manual
The Replace function replaces a specified part of a string with another string a specified number of times.
Syntax
Replace(string,find,replacewith[,start[,count[,compare]]])
| Parameters | Description |
|---|---|
| string | Required. The string to be searched. |
| find | Required. The part of the string to be replaced. |
| replacewith | Required. The substring used for the replacement. |
| 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. |
| The default value is -1, which means all possible replacements are performed. | |
| compare | Optional. Specifies the type of string comparison to use. The default is 0.
The following values can be used: |
Example
Example 1
Replace the word "beautiful" with "fantastic":
The example above produces the following output:
This is a fantastic day!
Try it »
Example 2
Replace the letter "i" with "##":
The example above produces the following output:
Th##s ##s a beaut##ful day!
Try it »
Example 3
Replace the letter "i" with "##", starting at position 15:
Note that all characters before position 15 will be removed.
The example above produces the following output:
t##ful day!
Try it »
Example 4
Starting at position 1, replace the first 2 letters "i" with "##":
The example above produces the following output:
Th##s ##s a beautiful day!
Try it »
Example 5
Replace the letter "t" with "##", using text and binary comparisons:
The example above produces the following output:
##his is a beau##iful day!
This is a beau##iful day!
Try it »
Complete VBScript Reference Manual