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