VBScript Replace-functie
Definitie en gebruik
De Replace-functie kan een string vervangen door een andere string een bepaald aantal keren.
Syntax
Replace(string,find,replacewith[,start[,count[,compare]]])
parameter |
Description |
string |
Verplicht. De string die moet worden gezocht. |
find |
Verplicht. Het deel van de te vervangen string. |
replacewith |
Verplicht. De te vervangen substring. |
start |
Optioneel. Definieert de startpositie. De standaardwaarde is 1. |
count |
Optional. Specifies the number of replacements to be made. The default is -1, indicating all possible replacements. |
compare |
Optional. Specifies the type of string comparison to be used. The default is 0. |
Value of parameter compare:
Constant |
Value |
Description |
vbBinaryCompare |
0 |
Execute binary comparison. |
vbTextCompare |
1 |
Execute text comparison. |
Possible values that Replace may return:
Possible values of parameters |
Value returned by Replace |
expression is zero-length |
Zero-length string ("") |
expression is Null |
Error. |
find parameter is zero-length |
Copy of expression. |
replacewith parameter is zero-length |
Copy of expression, with all content specified by the find parameter removed. |
start > Len(expression) |
Zero-length string. |
count is 0 |
Copy of expression. |
Instance
Example 1
dim txt
txt="This is a beautiful day!"
document.write(Replace(txt,"beautiful","horrible"))
Output:
This is a horrible day!