1 引言html
用windows自带的text文本在最前面会带入看不到的BOM,致使异常mysql
2 代码sql
package main import ( "strings" "fmt" ) func main(){ line := "// mysql数据库连接配置" if strings.EqualFold(line[:2], "//"){ fmt.Println("this is comment") }else{ fmt.Println("this is not comment") } }
运行结果以下:数据库
# command-line-arguments test\test\testFilterRemark.go:17:11: invalid BOM in the middle of the file Compilation finished with exit code 2
若是改成:(在文本上是看不出差别性的)windows
func main(){ line := "// mysql数据库连接配置" if strings.EqualFold(line[:2], "//"){ fmt.Println("this is comment") }else{ fmt.Println("this is not comment") } }
运行结果以下:bash
this is comment Process finished with exit code 0
3.扩展资料this
1.不要使用Windows自带记事本写代码( http://rabbitfeet.net/archives/144.html) .net