stringgoutf-8rune

Creating a substring in go creates a new kind of symbol


I am comparing strings and there is the following:

enter image description here

Please note that the " in front of NEW are different.

Now when calling my function like this:

my_func(a[18:], b[18:])

The resulting strings are surprisingly:

enter image description here

What do I have to do to cut this weird symbol away and why is it behaving like this?


Solution

  • Another option is the utf8string package:

    package main
    import "golang.org/x/exp/utf8string"
    
    func main() {
       s := utf8string.NewString(` 'Not Available') “NEW CREDIT" FROM customers;`)
       t := s.Slice(18, s.RuneCount())
       println(t == `“NEW CREDIT" FROM customers;`)
    }
    

    https://pkg.go.dev/golang.org/x/exp/utf8string