K
Kamalesh Paul
Guest
hi all,
If i have comma between the words, it is pushing the word after comma to next column. how to escape comma in CSV file so that the whole word stays in the same column.
For Example if i have "Spl , Character", character is going to next column. I want "spl , Character" to be in the same column.
Please see my code below. Can you guys modify my code to escape the comma. Appreciate your help.
CSV File data : MEA , MEA: Core Banking , ON186761 , Arab International Bank , Customer , \"AIB - Teller, Party and EQ Knowledge Services\" , Q3-2020.
Below code for ur reference :
string[] strArray;
char[] charArray = new char[] { ',' };
strLine = sr.ReadLine();
strArray = strLine.Split(charArray);
for (int x = 0; x <= strArray.GetUpperBound(0); x++)
{
dt.Columns.Add(strArray[x].Trim());
}
strLine = sr.ReadLine();
while (strLine != null)
{
strArray = strLine.Split(',');
DataRow dr = dt.NewRow();
for (int i = 0; i <= strArray.GetUpperBound(0); i++)
{
dr = strArray.Trim();
}
dt.Rows.Add(dr);
strLine = sr.ReadLine();
}
sr.Close();
Continue reading...
If i have comma between the words, it is pushing the word after comma to next column. how to escape comma in CSV file so that the whole word stays in the same column.
For Example if i have "Spl , Character", character is going to next column. I want "spl , Character" to be in the same column.
Please see my code below. Can you guys modify my code to escape the comma. Appreciate your help.
CSV File data : MEA , MEA: Core Banking , ON186761 , Arab International Bank , Customer , \"AIB - Teller, Party and EQ Knowledge Services\" , Q3-2020.
Below code for ur reference :
string[] strArray;
char[] charArray = new char[] { ',' };
strLine = sr.ReadLine();
strArray = strLine.Split(charArray);
for (int x = 0; x <= strArray.GetUpperBound(0); x++)
{
dt.Columns.Add(strArray[x].Trim());
}
strLine = sr.ReadLine();
while (strLine != null)
{
strArray = strLine.Split(',');
DataRow dr = dt.NewRow();
for (int i = 0; i <= strArray.GetUpperBound(0); i++)
{
dr = strArray.Trim();
}
dt.Rows.Add(dr);
strLine = sr.ReadLine();
}
sr.Close();
Continue reading...