go为什么不能获取字符串某个字符地址?go如此设定的目的是什么?
2条回答 默认 最新
- 关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率
oyljerry 2019-01-14 09:53最佳回答 专家已采纳这个是go的字符串规定的,因为它是immutable类型,所以让你取某个字符的地址,官方不觉得有啥意义
A string type represents the set of string values. A string value is a (possibly empty) sequence of bytes. Strings are immutable: once created, it is impossible to change the contents of a string. The predeclared string type is string.
The length of a string s (its size in bytes) can be discovered using the built-in function len. The length is a compile-time constant if the string is a constant. A string's bytes can be accessed by integer indices 0 through len(s)-1. It is illegal to take the address of such an element; if s[i] is the i'th byte of a string, &s[i] is invalid.
采纳该答案 已采纳该答案 专家已采纳评论解决 无用打赏举报微信扫一扫
分享评论登录 后可回复...
查看更多回答(1条)
报告相同问题?
提交
相关推荐 更多相似问题
- 2019-09-05 11:42回答 2 已采纳 Get rid of the scanner (you already said you prefer ReadLine()) and change your nextInt() function
- 2018-10-23 08:43回答 2 已采纳 The second one is more idiomatic because it satisfies Stringer interface. func (day Day) String()
- 2019-04-24 06:14回答 2 已采纳 You can use strconv.Itoa: byteArray := []byte("Hello, 世界-123..") for _, v := range byteArray {
- 2014-03-04 11:40回答 2 已采纳 Use the errors package to create new errors. err = errors.New("an error") The returned error ca
- 2017-11-15 04:30回答 1 已采纳 Use the standard quotedprintable package to encode the string: ... import ( "bytes" "mim
- 2014-05-25 15:59回答 3 已采纳 Using a map and 2 loops : play func check(s string) string { m := make(map[rune]uint, len(s))
- 2018-04-29 10:44回答 2 已采纳 There is no simple len(string) concept in Go. You either need the number of bytes in the string re
- 2019-05-15 01:24回答 2 已采纳 This should do it: func calcOrigBinaryLength(datas string) int { l := len(datas) // cou
- 2019-07-24 09:34回答 1 已采纳 You can make use MapKeys in reflect package to do that(ref: https://golang.org/pkg/reflect/#Value.
- 2016-02-07 19:07回答 1 已采纳 Ok, two things: You haven't "inherited" io.Writer (you simply stated that your struct contains a
- 没有解决我的问题, 去提问