arrayAll := []string{"a", "b", "c", "d", "e"}
x := p[arrayAll[i]-"a"]
go 不支持运算符“-”, 那么如何获取数组的索引:arrayAll[i]-"a"
最佳答案
如何在字符串上定义运算符 -
?调用 "Hello"-"World"
后你期望得到什么结果?
您是否尝试对单个字符进行操作?这是明确定义的,您可能期望 'c'-'a'
确实等于 2
。考虑:
arrayAll := []byte{'a', 'b', 'c'} (or simply "abc")
x := p[arrayAll[2] - 'a']
不管怎样,您很可能不想减去字符串,而是字符的整数表示。
关于go - 无效操作 : (operator - not defined on string),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29893723/