我有一些代码,不用于解析文本文件到词典的工作...解析文本文件导入词典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