正如標(biāo)題所說,我正在嘗試解析文件但忽略注釋(以 開頭#)或空行。我試圖為此創(chuàng)建一個系統(tǒng),但它似乎總是忽略它應(yīng)該忽略注釋和/或空行。lines := strings.Split(d, "\n")var output map[string]bool = make(map[string]bool)for _, line := range lines { if strings.HasPrefix(line, "#") != true { output[line] = true } else if len(line) > 0 { output[line] = true }}運(yùn)行時(這是函數(shù)的一部分),它輸出以下內(nèi)容This is the input ('d' variable):MinecraftZerg RushPokemon# HelloThis is the output when printed ('output' variable):map[Minecraft:true Zerg Rush:true Pokemon:true :true # Hello:true]我的問題是它仍然保留了 "" 和 "#Hello" 值,這意味著某些事情失敗了,我無法弄清楚的事情。那么,我做錯了什么,這保留了不正確的價值觀?
解析文件,忽略注釋和空行
慕尼黑8549860
2022-01-04 15:55:23