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")
	}
}

千万不要用window自带文本编辑器编辑配置文件或者代码

运行结果如下:

# 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")
	}
}

千万不要用window自带文本编辑器编辑配置文件或者代码

运行结果如下:

this is comment

Process finished with exit code 0 

3.扩展资料

1.不要使用Windows自带记事本写代码( http://rabbitfeet.net/archives/144.html)  

相关文章:

  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-02-11
  • 2021-12-03
猜你喜欢
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-01-04
  • 2021-08-05
相关资源
相似解决方案