Reputation: 12905
How do I remove all Unicode newlines from a UTF-8 string in GoLang? I found this answer for PHP.
Upvotes: 6
Views: 3928
Reputation: 99254
You can use strings.Map
:
func filterNewLines(s string) string {
return strings.Map(func(r rune) rune {
switch r {
case 0x000A, 0x000B, 0x000C, 0x000D, 0x0085, 0x2028, 0x2029:
return -1
default:
return r
}
}, s)
}
Upvotes: 5