M
Mohammad Nadeem Alam
Guest
Hi Everyone,
I have a data table and able to convert into a csv file. My requirement is make output as .txt file where each value should be under double quote. I am using standard C# code to convert data table into csv. When I change it into csv method in place of comma, with colon, I get below output. This is fine, but my requirement is put double quote for each value. In nut shell I have csv as colon separated and I need each value under double quote in .txt file. Please advise, how it can be done in better way
In below example each value is separated by colon.
2020;32106;;UK;151;;;;;CONS;;22057.41;abcd;10/02/2020;MX;; 2020;80113;;UK;151;;;;;CONS;504.06;;abcd;10/02/2020;MX;; 2020;80113;;UK;152;;;;;CONS;378.1;;abcd;10/02/2020;MX;;
Need output like below.
"2020";"32106";"";"UK";"151";"";"";"";"";"CONS";"";"22057.41";"abcd";"10/02/2020";"MX";"";" "2020";"80113";"";"UK";"151";"";"";"";"";"CONS";"504.06";"";"abcd";"10/02/2020";"MX";"";" "2020";"80113";"";"UK";"152";"";"";"";"";"CONS";"378.1";"";"abcd";"10/02/2020";"MX";"";"
I tried simple way to assign double quote by looping each value as below. But result is same.
public static DataTable ConvertToDoubleQuote(DataTable DT)
{
for (int i = 0; i < DT.Rows.Count; i++)
{
for (int j = 0; j < DT.Columns.Count; j++)
{
if (string.IsNullOrEmpty(DT.Rows[j].ToString()))
{
DT.Rows[j] = @"" + DT.Rows[j] + @"";
}
}
}
return DT;
}
Mohammad Nadeem Alam SME in Emirates NBD
Continue reading...
I have a data table and able to convert into a csv file. My requirement is make output as .txt file where each value should be under double quote. I am using standard C# code to convert data table into csv. When I change it into csv method in place of comma, with colon, I get below output. This is fine, but my requirement is put double quote for each value. In nut shell I have csv as colon separated and I need each value under double quote in .txt file. Please advise, how it can be done in better way
In below example each value is separated by colon.
2020;32106;;UK;151;;;;;CONS;;22057.41;abcd;10/02/2020;MX;; 2020;80113;;UK;151;;;;;CONS;504.06;;abcd;10/02/2020;MX;; 2020;80113;;UK;152;;;;;CONS;378.1;;abcd;10/02/2020;MX;;
Need output like below.
"2020";"32106";"";"UK";"151";"";"";"";"";"CONS";"";"22057.41";"abcd";"10/02/2020";"MX";"";" "2020";"80113";"";"UK";"151";"";"";"";"";"CONS";"504.06";"";"abcd";"10/02/2020";"MX";"";" "2020";"80113";"";"UK";"152";"";"";"";"";"CONS";"378.1";"";"abcd";"10/02/2020";"MX";"";"
I tried simple way to assign double quote by looping each value as below. But result is same.
public static DataTable ConvertToDoubleQuote(DataTable DT)
{
for (int i = 0; i < DT.Rows.Count; i++)
{
for (int j = 0; j < DT.Columns.Count; j++)
{
if (string.IsNullOrEmpty(DT.Rows[j].ToString()))
{
DT.Rows[j] = @"" + DT.Rows[j] + @"";
}
}
}
return DT;
}
Mohammad Nadeem Alam SME in Emirates NBD
Continue reading...