VBScript Replace 函數(shù)
定義和用法
Replace 函數(shù)可使用一個字符串替換另一個字符串指定的次數(shù)。
語法
Replace(string,find,replacewith[,start[,count[,compare]]])
參數(shù) |
描述 |
string |
必需的。需要被搜索的字符串。 |
find |
必需的。將被替換的字符串部分。 |
replacewith |
必需的。用于替換的子字符串。 |
start |
可選的。規(guī)定開始位置。默認(rèn)是 1。 |
count |
可選的。規(guī)定指定替換的次數(shù)。默認(rèn)是 -1,表示進(jìn)行所有可能的替換。 |
compare |
可選的。規(guī)定所使用的字符串比較類型。默認(rèn)是 0。 |
參數(shù) compare 的值:
常數(shù) |
值 |
描述 |
vbBinaryCompare |
0 |
執(zhí)行二進(jìn)制比較。 |
vbTextCompare |
1 |
執(zhí)行文本比較。 |
Replace 可能返回的值:
參數(shù)可能的取值 |
Replace 返回的值 |
expression 為零長度 |
零長度字符串 ("")。 |
expression 為 Null |
錯誤。 |
find 參數(shù)為零長度 |
expression 的副本。 |
replacewith 參數(shù)為零長度 |
expression 的副本,其中刪除了所有由 find 參數(shù)指定的內(nèi)容。 |
start > Len(expression) |
零長度字符串。 |
count 為 0 |
expression 的副本。 |
實例
例子 1
dim txt
txt="This is a beautiful day!"
document.write(Replace(txt,"beautiful","horrible"))
輸出:
This is a horrible day!