VBScript 교체 기능
❮ 완전한 VBScript 참조
Replace 함수는 문자열의 지정된 부분을 지정된 횟수만큼 다른 문자열로 바꿉니다.
통사론
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
위치 15에서 시작하여 문자 "i"를 "##"으로 바꿉니다.
위치 15 이전의 모든 문자가 제거됩니다.
<%
txt="This is a beautiful day!"
response.write(Replace(txt,"i","##",15))
%>
위 코드의 출력은 다음과 같습니다.
t##ful day!
실시예 4
위치 1에서 시작하여 문자 "i"의 첫 번째 2개 항목을 "##"으로 바꿉니다.
<%
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 참조