【问题标题】:Golang - Removing all Unicode newline characters from a stringGolang - 从字符串中删除所有 Unicode 换行符
【发布时间】:2016-11-13 07:48:35
【问题描述】:

如何从 GoLang 中的 UTF-8 字符串中删除所有 Unicode 换行符?我找到了this answer for PHP

【问题讨论】:

标签: go unicode utf-8


【解决方案1】:

你可以使用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)
}

playground

【讨论】:

    猜你喜欢
    • 2012-10-29
    • 1970-01-01
    • 2017-07-26
    • 2012-06-04
    • 1970-01-01
    • 2020-03-28
    相关资源
    最近更新 更多