千萬不要用window自帶文本編輯器編輯配置文件或者代碼


1 引言

用windows自帶的text文本在最前面會帶入看不到的BOM,導致異常

2 代碼

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  

如果改為:(在文本上是看不出差異性的)

func main(){
	line := "// mysql數據庫鏈接配置"
	if strings.EqualFold(line[:2], "//"){
		fmt.Println("this is comment")
	}else{
		fmt.Println("this is not comment")
	}
}

運行結果如下:

this is comment

Process finished with exit code 0 

3.擴展資料

1.不要使用Windows自帶記事本寫代碼( http://rabbitfeet.net/archives/144.html)  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM