I have a problem parsing a string in double. I have a line reading StreamWriter from a text file. The text file has the following lines:
17-09-2012: (100,98) 17-09-2012: (50,57)
Now I want to use the values โโfrom inside the brackets, add them together and display them in the text box. So far I have the following:
int counter = 0; double res = 0; string line; System.IO.StreamReader file = new System.IO.StreamReader("d:\\test.txt"); while ((line = file.ReadLine()) != null) { string par = Regex.Match(line, @"\(([^)]*)\)").Value; double par2 = double.Parse(par); res += par2; counter++; } file.Close(); textBox1.Text = res.ToString();
However, apparently, the input string is not in the correct format, which I find rather strange, since the regular expression should delete everything except the numbers inside the brackets. I even checked this by writing a line in a text box without adding them together, and showed "100,9850,57" . So, really, I donโt understand why it cannot convert a string to double.
Hope you can tell me what I'm doing wrong.
Robin source share