Golang-从字符串中删除所有Unicode换行符 [英] Golang - Removing all Unicode newline characters from a string

查看:686
本文介绍了Golang-从字符串中删除所有Unicode换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

您可以使用 strings.Map :

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

游乐场

这篇关于Golang-从字符串中删除所有Unicode换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆