I’d like to thank Stackoverflow member Pratap .R first because he helped me with the code. I’m still have a small formating issue with one of my replace functions. What is happening is when I replace </me> it replaces with ;. I can’t have the end of the row have a ; at the end.
using (FileStream strm = new FileStream(exportfile, FileMode.Create))
{
using (StreamWriter writer = new StreamWriter(strm))
{
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader reader = cmd.ExecuteReader();
for (int i = 0; i < reader.FieldCount; i++)
writer.Write((i == 0 ? "" : "|") + reader.GetName(i));
writer.Write("\n");
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
writer.Write
(
(i == 0 ? "" : "|") +
reader[i].ToString().Replace(@"<me> ","")
.Replace(@"</me>", "|").Replace(@"</me>", ";")
.Replace('\n', ' ').Replace('\r', ' ')
);
}
writer.WriteLine();
}
reader.Close();
}
}
So you can see when it occurs with it’s replaced with “;”. I can’t have a ; end the row. Any suggestions or tips always appricated.
Stringobjects also have a wonderfulTrimEnd()function