VBScript InStr 함수
❮ 완전한 VBScript 참조
InStr 함수는 다른 문자열 내에서 한 문자열이 처음 나타나는 위치를 반환합니다.
InStr 함수는 다음 값을 반환할 수 있습니다.
- string1이 ""인 경우 - InStr은 0을 반환합니다.
- string1이 Null인 경우 - InStr은 Null을 반환합니다.
- string2가 ""인 경우 - InStr은 시작을 반환합니다.
- string2가 Null인 경우 - InStr이 Null을 반환합니다.
- string2를 찾을 수 없는 경우 - InStr은 0을 반환합니다.
- string2가 string1 내에 있는 경우 - InStr은 일치하는 항목이 있는 위치를 반환합니다.
- 시작 > Len(string1)인 경우 - InStr은 0을 반환합니다.
팁: InStrRev 함수도 살펴보십시오.
통사론
InStr([start,]string1,string2[,compare])
Parameter | Description |
---|---|
start | Optional. Specifies the starting position for each search. The search begins at the first character position (1) by default. This parameter is required if compare is specified |
string1 | Required. The string to be searched |
string2 | Required. The string expression to search for |
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(InStr(txt,"beautiful"))
%>
위 코드의 출력은 다음과 같습니다.
11
실시예 2
다른 시작 위치를 사용하여 문자 "i" 찾기:
<%
txt="This is a beautiful day!"
response.write(InStr(1,txt,"i") & "<br />")
response.write(InStr(7,txt,"i") & "<br />")
%>
위 코드의 출력은 다음과 같습니다.
3
16
실시예 3
텍스트 및 이진 비교로 문자 "t" 찾기:
<%
txt="This is a beautiful day!"
response.write(InStr(1,txt,"t",1) & "<br />")
response.write(InStr(1,txt,"t",0) & "<br />")
%>
위 코드의 출력은 다음과 같습니다.
1
15
❮ 완전한 VBScript 참조