第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

范圍 []字符串返回 uint8

范圍 []字符串返回 uint8

Go
慕虎7371278 2022-09-26 15:54:02
我有一個 yaml 文件,當(dāng)前寫為:resource:      File:        containment_path:        - File        - File::Value      Default:        containment_path:        - Default        - Default::Echo        - Default[main]      Exec:        containment_path:        - Stage        - Exec::File        - Exec[File]我使用結(jié)構(gòu)來獲取containment_path:type Yaml struct {    ContainmentPath      []string      `yaml:"containment_path"`}我想超越遏制路徑的范圍,以獲取containment_path中的第二個值:文件::值,默認::回聲,執(zhí)行::文件我做這個代碼:for _, v := range m.ContainmentPath {    spew.Dump("Value ContainmentPath:", m.ContainmentPath)    spew.Dump("Value v[1]:", v[1])          value = v[1]}當(dāng)我運行它時,我得到這個遏制路徑:(string) (len=8) "Value ContainmentPath:"([]string) (len=2 cap=2) { (string) (len=4) "File", (string) (len=11) "File::Value"}(string) (len=8) "Value ContainmentPath:"([]string) (len=3 cap=3) { (string) (len=7) "Default", (string) (len=13) "Default::Echo", (string) (len=13) "Default[main]"}(string) (len=8) "Value ContainmentPath:"([]string) (len=3 cap=3) { (string) (len=5) "Stage", (string) (len=10) "Exec::File", (string) (len=10) "Exec[File]"}當(dāng)我運行它時,我得到了v[1]的這個:(string) (len=11) "Value v[1]:"(uint8) 114(string) (len=11) "Value v[1]:"(uint8) 105(string) (len=11) "Value v[1]:"(uint8) 116我想得到v[1]的值: 文件::值, 默認::回聲, 執(zhí)行::文件我如何在Go中執(zhí)行此操作?謝謝
查看完整描述

1 回答

?
慕神8447489

TA貢獻1780條經(jīng)驗 獲得超1個贊

您正在索引到字符串,而不是 [] 字符串。

ContainmentPath是字符串的一段。

運行 時,將采用切片中每個字符串的值。類型也是如此。for _, v := range m.ContainmentPathvvstring

當(dāng)您打印時,您正在索引字符串(沒有先檢查其長度,非常糟糕的想法)并打印字符串中的第二個字符,這是一個字節(jié)。字節(jié)只是 uint8 的別名。v[1]


查看完整回答
反對 回復(fù) 2022-09-26
  • 1 回答
  • 0 關(guān)注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號