Overview and Actualizing the Topic

Hello, learners! In today's session, we will explore searching and replacing strings in Go. Imagine this scenario: you're operating a chat service and need to filter and replace certain inappropriate words. This lesson will show you how to accomplish this task using Go's standard strings package.

String Searching: the `strings.Index` and `strings.LastIndex` Functions

Let's start with string searching. Go offers the strings.Index and strings.LastIndex functions. strings.Index returns the index of the first occurrence of a substring, while strings.LastIndex provides the index of the last.

In this example, the string "CodeSignal" begins at index seven in our string.

Notice how "CodeSignal" starts at index 26 in the last instance within our string. Efficient, isn't it?

Checking Substring Existence: the `strings.Contains` Function
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal