TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Navin kumar
NA
13
9.2k
How to escape comma in csv file without using double quotes/" in C#
Sep 18 2020 12:59 AM
I am able to escape comma between strings with using double quotes such as strings are:"Laxchaman","Bharath","satrudhan" was brother of Ram.It is working fine in csv file But when i am copy the string from the csv cell to notepad it is showing """Laxchaman"",""Bharath"",""satrudhan"" was brother of Ram". That's why the csv file is not being upload in SQL. I want String must be write in csv file with comma as same as sentences in real form.
using
(DataTable dt =
new
DataTable())
{
dt.Load(reader);
Console.WriteLine(dt.Rows.Count);
//check its filled
StringBuilder sb =
new
StringBuilder();
string
sbb =
""
;
sb.AppendLine(
string
.Join(
","
, dt.Columns.Cast<datacolumn>().Select(c => c.ColumnName)));
sb.Remove(sb.Length - 1, 1);
foreach
(DataRow row
in
dt.Rows)
{
for
(
int
i = 0; i < dt.Columns.Count; i++)
{
if
(row[i].ToString().Contains(
","
))
{
sb.Append(String.Format(
"\"{0}\","
, row[i]));
}
else
{
sb.Append(row[i].ToString() +
","
);
}
}
sb.AppendLine();
}
ArrayList ar =
new
ArrayList();
File.WriteAllText(@
"D:\ISR\1"
+
".csv"
, sb.ToString());
}
Reply
Answers (
2
)
how to compress or reduce size of video in asp.net core mvc
Cascade delete in asp.net