VBScript vervang funksie
❮ Voltooi VBScript-verwysing
Die Vervang-funksie vervang 'n gespesifiseerde deel van 'n string met 'n ander string 'n gespesifiseerde aantal kere.
Sintaksis
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:
|
Voorbeelde
Voorbeeld 1
Vervang die woord "mooi" met "fantasties":
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"beautiful","fantastic"))
%>
Die afvoer van die kode hierbo sal wees:
This is a fantastic day!
Voorbeeld 2
Vervang die letter "i" met "##":
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"i","##"))
%>
Die afvoer van die kode hierbo sal wees:
Th##s ##s a beaut##ful day!
Voorbeeld 3
Vervang die letter "i" met "##", begin by posisie 15:
Let daarop dat alle karakters voor posisie 15 verwyder word.
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"i","##",15))
%>
Die afvoer van die kode hierbo sal wees:
t##ful day!
Voorbeeld 4
Vervang die 2 eerste voorkoms van die letter "i" met "##", begin by posisie 1:
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"i","##",1,2))
%>
Die afvoer van die kode hierbo sal wees:
Th##s ##s a beautiful day!
Voorbeeld 5
Vervang die letter "t" met "##", met tekstuele, en binêre, vergelyking:
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"t","##",1,-1,1) & "<br />")
response.write(Replace(txt,"t","##",1,-1,0))
%>
Die afvoer van die kode hierbo sal wees:
##his is a beau##iful day!
This is a beau##iful day!
❮ Voltooi VBScript-verwysing