【发布时间】:2017-06-15 15:43:55
【问题描述】:
func lengthOfLongestSubstring(s string) {
match := make(map[string]int)
var current string
current = s[0]
if match[current] == 1 {
///
}
}
为什么我会收到错误 cannot use s[0] (type byte) as type string in assignment?据我所知,很明显s 是string 类型,为什么访问一个字符会变成byte 类型?
【问题讨论】:
-
将 s[0] 转换为字符串是否有效?
-
因为
s[0]是byte,而不是string。您确定要仅对字节进行操作,还是应该使用 utf8 符文? -
如果您已经解决了自己的问题,请提供您自己的答案。
标签: go