go strconv.CanBackquote()方法

strconv.CanBackquote()方法

Golang的strconv标准库模块中的CanBackquote()方法,可用于检查字符串是否可以不变地表示为单行的无空格和tab之外控制字符的反引号字符串。


语法

func CanBackquote(s string) bool

go源码中对CanBackquote()方法的介绍:

CanBackquote reports whether the string s can be represented unchanged as a single-line backquoted string without control characters other than tab.

参数

参数描述
s字符串类型string

返回值

bool布尔类型值,true or false。


strconv.CanBackquote()方法实例代码

func main() {
	str1 := "笨鸟工具,x1y1z1.com"
	var t1 bool = strconv.CanBackquote(str1)
	str2 := `"abc"`
	t2 := strconv.CanBackquote((str2))
	str3 := "`hello`"
	t3 := strconv.CanBackquote(str3)
	fmt.Println(t1)
	fmt.Println(t2)
	fmt.Println(t3)
}
//命令行输入运行go文件的命令,比如:go run test.go,得到输出:
true
true
false

全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.