0
タイトルには、ファイルを解析していますが、コメントは無視されています(#
で始まる)または空白行は無視されています。私はこのためのシステムを作ろうとしましたが、コメントや空白行を無視するべきであると常に無視しているようです。ファイルを解析してコメントと空白を無視する
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
}
}
(これは機能の一部である)を実行すると、それはここでは、次の
This is the input ('d' variable):
Minecraft
Zerg Rush
Pokemon
# Hello
This is the output when printed ('output' variable):
map[Minecraft:true Zerg Rush:true Pokemon:true :true # Hello:true]
私の問題は、それはまだその何かを意味し、「」と「#こんにちは」の値を保持していることである出力失敗した、私が把握できなかった何か。
これは不適切な値を保持するのは間違っていますか?
マイナーな最適化は '' len(line)> 0 && line [0]!= '#' {...} 'になります。 – OneOfOne