Функция замены VBScript
❮ Полный справочник VBScript
Функция замены заменяет указанную часть строки другой строкой указанное количество раз.
Синтаксис
Replace(string,find,replacewith[,start[,count[,compare]]])
Parameter | Description |
---|---|
string | Required. The string to be searched |
find | Required. The part of the string that will be replaced |
replacewith | Required. The replacement substring |
start | Optional. Specifies the start position. Default is 1. All characters before the start position will be removed. |
count | Optional. Specifies the number of substitutions to
perform. Default value is -1, which means make all possible substitutions |
compare | Optional. Specifies the string comparison to use.
Default is 0 Can have one of the following values:
|
Примеры
Пример 1
Замените слово «красивый» на «фантастический»:
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"beautiful","fantastic"))
%>
Вывод кода выше будет:
This is a fantastic day!
Пример 2
Замените букву «i» на «##»:
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"i","##"))
%>
Вывод кода выше будет:
Th##s ##s a beaut##ful day!
Пример 3
Замените букву «i» на «##», начиная с позиции 15:
Обратите внимание, что все символы до позиции 15 удаляются.
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"i","##",15))
%>
Вывод кода выше будет:
t##ful day!
Пример 4
Замените 2 первых вхождения буквы «i» на «##», начиная с позиции 1:
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"i","##",1,2))
%>
Вывод кода выше будет:
Th##s ##s a beautiful day!
Пример 5
Замените букву «t» на «##», с текстовым и двоичным сравнением:
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"t","##",1,-1,1) & "<br />")
response.write(Replace(txt,"t","##",1,-1,0))
%>
Вывод кода выше будет:
##his is a beau##iful day!
This is a beau##iful day!
❮ Полный справочник VBScript