Reputation: 18221
What is the most straightforward way to replace HTML entities with their string representations in a Go string
? That is, how would I turn the string Rø&d grød & fløde
into Rød grød & fløde
?
My own solutions have been either using strings.Replace
on all relevant entities (which quickly becomes intractable), or wrapping the string into an XML document and decoding it with xml.Decoder
(which seems silly and leads to numerous edge cases).
Upvotes: 15
Views: 8621
Reputation: 121099
Use the html.UnescapeString function:
fmt.Println(html.UnescapeString("Rø&d grød & fløde"))
Upvotes: 25