Have a csv file in the following format:
a,b
Goal is to store this csv file in a dictionary
Problem: csvOne has this as first field
kfjdfdsdsd, second value
aaaaaaa
sdasdasdaasdasdfffw
as a result it does not get stored in it's original format, i.e. only the below part gets stored:
key: "", value: kfjdfdsdsd
My code:
public void StoreInDictionary(string[] file, Dictionary<string, string> dictionary)
{
foreach (var line in file)
{
var cleansedLine = Regex.Replace(line, @"\s+", "");
var commaIndex = cleansedLine.IndexOf(',');
var valueOne = cleansedLine.Substring(0, commaIndex + 1);
var valueTwo = cleansedLine.Substring(commaIndex + 1);
if (!dictionary.ContainsKey(valueOne))
{
dictionary.Add(valueOne, valueTwo);
}
}
}
p.s. tried Replace \r\n too, did not work
Thanks a lot