--- type: "fhirpath-function" title: "FHIRPath Function: indexOf" function: "indexOf" category: "String Manipulation" section: "5.6.1" source: "fhirpath/functions.json" --- # FHIRPath Function: indexOf Returns the 0-based index of the first position `substring` is found in the input string, or -1 if it is not found. If `substring` is an empty string (`''`), the function returns 0. If the input or `substring` is empty (`{ }`), the result is empty (`{ }`). If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment. ``` fhirpath 'abcdefg'.indexOf('bc') // 1 'abcdefg'.indexOf('x') // -1 'abcdefg'.indexOf('abcdefg') // 0 ``` ## Summary - **Category**: String Manipulation - **Section**: `5.6.1` - **Return Type**: `Integer` - **Empty Input Result**: `empty` - **Errors on Multiple Input**: `true` ## Description Returns the 0-based index of the first position `substring` is found in the input string, or -1 if it is not found. ## Arguments - `substring`: `String` - Substring to find ## Type Mapping - `String-Integer` ## Example ```fhirpath 'abcdefg'.indexOf('bc') // 1 'abcdefg'.indexOf('x') // -1 'abcdefg'.indexOf('abcdefg') // 0 ```