Golang - 从字符串中删除所有 Unicode 换行符

dha*_*0us 5 unicode utf-8 go

如何从 GoLang 的 UTF-8 字符串中删除所有 Unicode 换行符?我为 PHP找到了这个答案

One*_*One 5

您可以使用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)
}
Run Code Online (Sandbox Code Playgroud)

playground