dounaoji2054 2016-07-11 11:20
浏览 512
已采纳

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

How do I remove all Unicode newlines from a UTF-8 string in GoLang? I found this answer for PHP.

  • 写回答

1条回答 默认 最新

  • dongtai6741 2016-07-11 14:28
    关注

    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)
    }
    

    <kbd>playground</kbd>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?