我正在查看 string.Map
函数,它必须采用返回 rune 的映射函数。我想通过调用来消除解析为 false 的 rune :unicode.IsPrint()
func Map(映射 func(rune) rune, s string) string
我的函数看起来像这样:
func main() {
func CleanUp(s string) string {
clean := func(r rune) rune {
if unicode.IsPrint(r) || r == rune('\n') {
return r
}
return rune('')
}
strings.Map(clean, s)
}
它应该将像这样的 "helloworld '\x10"
清理成 "helloworld ' "
但是 rune('')
是无效的。如何返回空白或空 rune ?
最佳答案
如果你想消除 rune ,“空白 rune ”不是办法。那不会消除任何东西。
假设您正在谈论 strings.Map
,文档说
If mapping returns a negative value, the character is dropped from the string with no replacement.
让您的映射器返回负值以指示应丢弃 rune 。
关于go - 如何返回空白 rune ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52174097/