Skip to content

StringUtils.lastIndexOfIgnoreCase

Signature: StringUtils.lastIndexOfIgnoreCase(inputString, searchString, startPosition*)

Returns: Integer index - the last index of the searchString ignoring the case, -1 if no match or null inputString

Finds the last index within the inputString, handling null ignoring the case. A null inputString will return -1. A negative startPosition returns -1. An empty ("") searchString always matches unless the startPosition is negative. A startPosition greater than the inputString length searches the whole string.

Note

startPosition is optional. When not specified, {end of string} starts the search at the end of the inputString and runs backwards.

Parameters

Type Name Description Default
String inputString the String to check, may be null
String searchString the String to find, may be null
Integer startPosition* (optional) the start position, negative treated as zero {end of string}

Example

// Example: case-insensitive lastIndexOfIgnoreCase with optional startPosition (null-safe).

var input = "One TWO three two ONE";

StringUtils.lastIndexOfIgnoreCase(input, "one");        // 18  (matches "ONE")
StringUtils.lastIndexOfIgnoreCase(input, "TWO");        // 14  (matches "two")
StringUtils.lastIndexOfIgnoreCase(input, "two", 10);    // 4   (limits search before index 10)
StringUtils.lastIndexOfIgnoreCase(null, "one");         // -1