我正在从“Head First Go”学习 Go 语言,并在第 2 章遇到了一个示例
package main
import (
"fmt"
"strings"
)
func main(){
var broken string = "Go# R#cks!"
//**Below line doesn't work, getting error as shown after the program :**-
var replacer strings.Replacer = strings.NewReplacer("#", "o")
// Whereas this line works perfectly
replacer := strings.NewReplacer("#", "o")
var fixed string = replacer.Replace(broken)
fmt.Println(replacer.Replace(fixed))
}
命令行参数 ./hello.go:10:6: 不能使用 strings.NewReplacer("#", "o") (type *strings.Replacer) 作为类型 strings.Replacer 赋值
收到一只叮咚
慕田峪9158850
相关分类