6

I have a string stored as a:

a := `M\u00fcnchen`
fmt.Println(a)  // prints "M\u00fcnchen"
b := "M\u00fcnchen"
fmt.Println(b)  // prints "München"

Is there a way I can convert a into b ?

kostix
  • 51,517
  • 14
  • 93
  • 176
Daniele B
  • 19,801
  • 29
  • 115
  • 173

1 Answers1

12

You can use strconv.Unquote for this:

u := `M\u00fcnchen`
s, err := strconv.Unquote(`"` + u + `"`)
if err != nil {
    // ..
}
fmt.Printf("%v\n", s)

Outputs:

München
cnicutar
  • 178,505
  • 25
  • 365
  • 392