To find the kth index of a character in a string in Go, you can use the strings.Index()
function. Here is an example:
main.go400 chars27 lines
In the example above, we use a loop to find the kth index of the 'o' character in the string "Hello, world!". We increment the starting index i by 1 each time we call strings.Index()
to find the next occurrence of 'o'. If we cannot find a kth occurrence of 'o', we display a message indicating that it was not found.
gistlibby LogSnag