--- type: "fhirpath-function" title: "FHIRPath Function: lastIndexOf" function: "lastIndexOf" category: "String Manipulation" section: "5.6.2" source: "fhirpath/functions.json" --- # FHIRPath Function: lastIndexOf {:.stu} > **Note:** The contents of this section are Standard for Trial Use (STU) {: .stu-note } Returns the 0-based index of the last position `substring` is found in the input string, or -1 if it is not found. {:.stu} If `substring` is an empty string (`''`), the function returns the length of the string. {:.stu} If the input or `substring` is empty (`{ }`), the result is empty (`{ }`). {:.stu} If the input collection contains multiple items, the evaluation of the expression will end and signal an error to the calling environment. {:.stu} ``` fhirpath 'abcdefg'.lastIndexOf('bc') // 1 'abcdefg'.lastIndexOf('x') // -1 'abcdefg'.lastIndexOf('abcdefg') // 0 'abc abc'.lastIndexOf('a') // 4 '0123'.lastIndexOf('') // 4 '0'.lastIndexOf('') // 1 ''.lastIndexOf('') // 0 ``` {:.stu} ## Summary - **Category**: String Manipulation - **Section**: `5.6.2` - **Return Type**: `Integer` - **Empty Input Result**: `empty` - **Errors on Multiple Input**: `true` ## Description Returns the 0-based index of the last 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'.lastIndexOf('bc') // 1 'abcdefg'.lastIndexOf('x') // -1 'abc abc'.lastIndexOf('a') // 4 ```