How to Check for Case-Insensitive Substrings in Go: Best Practices for 'golang string fold contains'?

9 Replies, 1535 Views

If you’re okay with using external packages, check out `golang.org/x/text/cases`. It’s more robust for case-insensitive stuff.

For golang string fold contains, you can do:

```go
import "golang.org/x/text/cases"

func foldContains(main, sub string) bool {
c := cases.Fold()
return strings.Contains(c.String(main), c.String(sub))
}
```
It’s a bit heavier but handles edge cases better.

Messages In This Thread



Users browsing this thread: 1 Guest(s)