我有一些代碼,不用於解析文本文件到詞典的工作...解析文本文件導入詞典C#<string><int>
Dictionary<string, int> dictDSDRecordsByValidCompCode = new Dictionary<string, int>(); // This dictionary will get rid of pipe delimited comp codes, get distinct, and keep cuont of how many DSD records per Comp Code
if (LineToStartOn.pInt > 0)
{
using (var sr = new StreamReader("\\rvafiler1\rdc\clients\sams\pif\DSD_Dictionary.txt"))
{
string line = null;
string key = null;
int value = 0;
// while it reads a key
while ((line = sr.ReadLine()) != null)
{
// add the key and whatever it
// can read next as the value
dictDSDRecordsByValidCompCode.Add(key, sr.ReadBlock);
dictDSDRecordsByValidCompCode.Add(value, sr.ReadBlock());
}
}
}
最後一行是它失敗。它不喜歡dictionay.Add(Line,sr.ReadBlock())語句。我哪裏錯了?
我需要讀取一個字符串後跟一個int ,.
,因爲你必須定義詞典中和sr.ReadLine()返回字符串,而不是int –
codebased
2014-11-24 12:59:08
爲了澄清,你是否想要統計文件中同一行的出現次數? – 2014-11-24 13:12:38