LastIndex()
Published Sep 26, 2023
Contribute to Docs
The LastIndex()
function returns the index value of the last occurrence of a substring in the original string. Otherwise, it returns -1
if the substring is not present in the original string.
Syntax
strings.LastIndex(str, substr)
Where str
is the original string and substr
is the substring to find in the original string.
Example
The following example demonstrates the use of the strings.LastIndex()
function:
package mainimport ("fmt""strings")func main() {fmt.Println(strings.LastIndex("flibbertigibbet ", "bbe"))}
The output will be:
11
Codebyte Example
The provided example is executable and implements the strings.LastIndex()
function.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.