Gih's Blog

只言片语

Strip chars from a string in Go.

2014-07-22 by gihnius, tagged as go
import (
    "fmt"
    "strings"
)

func stripchars(str, chr string) string {
    return strings.Map(func(r rune) rune {
        if strings.IndexRune(chr, r) < 0 {
            return r
        }
        return -1
    }, str)
}