VBScript Değiştirme İşlevi
❮ Komple VBScript Referansı
Değiştir işlevi, bir dizenin belirtilen bir bölümünü belirtilen sayıda başka bir dizeyle değiştirir.
Sözdizimi
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:
|
Örnekler
örnek 1
"Güzel" kelimesini "fantastik" ile değiştirin:
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"beautiful","fantastic"))
%>
Yukarıdaki kodun çıktısı şöyle olacaktır:
This is a fantastic day!
Örnek 2
"i" harfini "##" ile değiştirin:
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"i","##"))
%>
Yukarıdaki kodun çıktısı şöyle olacaktır:
Th##s ##s a beaut##ful day!
Örnek 3
15 konumundan başlayarak "i" harfini "##" ile değiştirin:
15. pozisyondan önceki tüm karakterlerin kaldırıldığını unutmayın.
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"i","##",15))
%>
Yukarıdaki kodun çıktısı şöyle olacaktır:
t##ful day!
Örnek 4
1. konumdan başlayarak "i" harfinin ilk 2 yerini "##" ile değiştirin.
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"i","##",1,2))
%>
Yukarıdaki kodun çıktısı şöyle olacaktır:
Th##s ##s a beautiful day!
Örnek 5
"t" harfini "##" ile, metinsel ve ikili karşılaştırma ile değiştirin:
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"t","##",1,-1,1) & "<br />")
response.write(Replace(txt,"t","##",1,-1,0))
%>
Yukarıdaki kodun çıktısı şöyle olacaktır:
##his is a beau##iful day!
This is a beau##iful day!
❮ Komple VBScript Referansı