simplfuzz
simplfuzz

Reputation: 12905

Golang - Removing all Unicode newline characters from a string

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

Upvotes: 6

Views: 3928

Answers (1)

OneOfOne
OneOfOne

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

playground

Upvotes: 5

Related Questions