다음을 통해 공유


indexof() (컬렉션에서 특정 요소의 인덱스를 찾는 메서드)

적용 대상: ✅Microsoft Fabric

입력 문자열 내에서 지정된 문자열이 처음 나타나는 인덱스(0부터 시작)를 보고합니다. indexof() 함수는 대/소문자를 구분합니다. 대/소문자를 구분하지 않는 검색을 수행하려면 두 입력을 모두 사용 tolower() 하거나 toupper() 사용하는 것이 좋습니다.

자세한 내용은 indexof_regex()를 참조하세요.

구문

indexof( 문자열,일치[,시작[,길이 발생[,]]])

구문 규칙에 대해 자세히 알아봅니다.

매개 변수

이름 유형 필수 설명
문자열 string ✔️ 검색할 원본 문자열입니다.
성냥 string ✔️ 검색할 문자열입니다.
start int 검색 시작 위치입니다. 음수 값은 문자열의 끝에서
길이 int 검사할 문자 위치의 수입니다. 값이 -1이면 길이가 무제한입니다.
발생 int 발생 횟수입니다. 기본값은 1입니다.

참고 항목

문자열 또는 일치 항목이 형식이 아닌 경우

반품

일치 항목의 인덱스 위치(0부터 시작하는 인덱스)입니다.

  • 문자열에서 일치 항목을 찾을 수 없으면 -1을 반환합니다.
  • 다음 경우를 반환합니다.null
    • 시작 이 0보다 작습니다.
    • 발생 이 0보다 작습니다.
    • 길이 가 -1보다 작습니다.

예제

print
 idx1 = indexof("abcdefg","cde")    // lookup found in input string
 , idx2 = indexof("abcdefg","cde",1,4) // lookup found in researched range 
 , idx3 = indexof("abcdefg","cde",1,2) // search starts from index 1, but stops after 2 chars, so full lookup can't be found
 , idx4 = indexof("abcdefg","cde",3,4) // search starts after occurrence of lookup
 , idx5 = indexof("abcdefg","cde",-5)  // negative start index
 , idx6 = indexof(1234567,5,1,4)       // two first parameters were forcibly casted to strings "12345" and "5"
 , idx7 = indexof("abcdefg","cde",2,-1)  // lookup found in input string
 , idx8 = indexof("abcdefgabcdefg", "cde", 1, 10, 2)   // lookup found in input range
 , idx9 = indexof("abcdefgabcdefg", "cde", 1, -1, 3)   // the third occurrence of lookup is not in researched range

출력

idx1 idx2 idx3 idx4 idx5 idx6 idx7 idx8 idx9
2 2 -1 -1 2 4 2 9 -1