String golang在编译时删除常量字符串中的字符(用于可读性)(空格,\n和\t)
空格有助于缩进URL和sql查询,使其更具可读性。 在golang中,有没有办法在编译时从常量字符串中删除字符String golang在编译时删除常量字符串中的字符(用于可读性)(空格,\n和\t),string,go,constants,String,Go,Constants,空格有助于缩进URL和sql查询,使其更具可读性。 在golang中,有没有办法在编译时从常量字符串中删除字符 ex: (runtime version) const url = `https://example.com/path? attr1=test &attr2=test ` // this is the code to be replaced urlTrim := strings.Replace( strings.Replace(url, "\n", "", -1) ) 不能包
ex: (runtime version)
const url = `https://example.com/path?
attr1=test
&attr2=test
`
// this is the code to be replaced
urlTrim := strings.Replace(
strings.Replace(url, "\n", "", -1)
)
不能包含函数调用(少数内置函数除外)。所以,你想要的东西不能用计算机来完成
如果您使用多行的目的只是为了可读性,那么只需使用多个文本,并将它们:
试穿一下
见相关问题:
const url = "https://example.com/path?" +
"attr1=test" +
"&attr2=test"