Okay, so to keep this short, here is my issue. Apologies in advance since I'm not next to my workstation and can't attach images from the debugger as I had originally planned.
My job requires us to work with a large amount of CSV/Excel files. We take those files, put them in one of our programs that changes the format and whatnot, and then we insert those files into our database to generate reports.
A short description of my program: it needs to validate if a CSV file has the correct headers before we do any further manipulation to it. It needs to have a cell with some text and a number. In case that number is not there the program reads it from another line in the file, since it exists there and I just use that value to create the header manually.
Whenever I read the value from the file, I get the value I need, but it has an unwanted backslash. Unfortunately I can't attach a picture from the debugger, but it looks something like what's in the parantheses(""11111111""). Now as some others have mentioned in other threads, when I print the value to the console or even to a message box, the slashes and the extra quotation marks are not there. I need to convert the value into a number, so I tried using string.Repalce() in order to get rid of the slash and the extra quotation marks.
I can do this:
accountNo = accountNo.Replace(@"\", "");
But that doesn't solve the problem of the extra quotation marks. Because when I try and do this:
accountNo = accountNo.Replace(@"\"", "");
I get syntax errors and my program crashes. Now I know that Excel doesn't show quotes unless you use double quotes, and since a CSV file is like a text file, C#'s StreamReader just reads the file with the quotes as a value and then wraps it in another set of quotes by default because that variable is a string.
Is there a reliable way to get rid of the backslash and the extra quotation marks? I thought about maybe using Regex, but I don't know Regex at all...
Thanks!