VBScript Replace 函數
定義和用法
Replace 函數可用一個字串替換另一個字串指定的次數。
語法
Replace(string,find,replacewith[,start[,count[,compare]]])
參數 |
Description |
string |
必需的。需要被搜索的字符串。 |
find |
必需的。將被替換的字符串部分。 |
replacewith |
必需的。用於替換的子字串。 |
開始 |
可選的。規定開始位置。默認是 1。 |
count |
Optional. Specifies the number of replacements to be made. The default is -1, indicating all possible replacements should be made. |
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 can 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:
Ito ay isang kahinatnan na araw!