Is there someone who have come across this situation.
Recently in one of my application i have to parse a CSV file and insert directly into the DB.
There was a lot null values in the CSV, so I had to replace it with "NULL" before inserting into the DB.
ie. if the CSV string contains the data
"123,"XXXXX",,,1"
My replacement would be
"123,"XXXXX",NULL,NULL,1"
But when using the replace functon
Code:
strCSVString.Replace(",,",",NULL,");
the result was
"123,"XXXXX",NULL,,1"
It took quite a while for me to realise that I had to use the replace function twice to do this.
ie.
When I used
strCSVString =
Code:
strCSVString.Replace(",,",",NULL,");
strCSVString =
Code:
strCSVString.Replace(",,",",NULL,");
it gave me the required output
"123,"XXXXX",NULL,NULL,1"
Is there something which I missing out here?
OR is it a bug with C#.NET?
I'm a regular customer to the replace funtion (When dealing with ASP,PHP,Coldfusion etc).. And when coming to C# it is really creating me a lot of problems...
Please let me know if anyone can throw a light on this issue.