Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm reading a CSV-File (5MB) with File.ReadAllLines(FileName). On my local system it works perfectly but on the customers system it removes the leading zeros of the line. There are no third party modules involved and I can't understand the behavior since it's plain string all the time.

C#
private static string getCSVLine(string value, string[] _csvFileArray)
        {
            string csvLine = null;

            foreach (string line in _csvFileArray)
            {
                if (!line.StartsWith("#"))
                {
                    string[] csvLineSplit = line.Split(';');
                    if (value == csvLineSplit[0])
                    {
                        csvLine = line.Replace("\"", null);                   
                        return csvLine;
                    }
                }
            }
            return null;
        }


It's running as a service. The value in this method is correct and needs to match the first value of the line split. But all lines beginning with zeros are not being matched.

Example line of the CSV:

0000148542;234258;1000000010;"n";2003;"Cologne";"Name, Lastname";0;19461123

Edit: The title was misleading.. the leading zeros are being removed when held in a string array. The original csv file keeps untouched.

What I have tried:

Tested on my own system. Lines beginning with zeros are being read correctly. Differences between the two systems is that I'm working on Windows 7 and the customer runs the service at a Windows Server 2008 R2.
Posted
Updated 18-Feb-16 21:34pm
v3
Comments
Richard Deeming 19-Feb-16 11:25am    
Are you sure that's what's in the CSV file on the customer's system? If your customer has opened the file in Excel and saved it again, that might have stripped the leading zeros from the numbers.

1 solution

That code won't remove the leading zeros - it can't because all it does is split out by semicolons, and remove double quotes.
So look at what happens before and after this: and at where the "value" parameter comes from. If that is being generated from an integer, then local culture settings may produce a different string to that you expect or get on your system. For example, it may include thousands separators, which would cause a non-match.

But it isn't that code!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900