I have DataTable
which retrieves multiple columns and rows. One of its column ("Comments") Contains data *
. I want replace that character with \n
.
dtOutput = Generix.getTickets(DateTime.Parse("1-1-1900"), DateTime.Now,"",iTicket, "", "", "", "","",iDispatched,uCode);
string sOutput = "";
foreach (DataRow drOutput in dtOutput.Rows)
{
sOutput += ((sOutput == "") ? "" : "~");
foreach (DataColumn dcOutput in dtOutput.Columns)
{
sOutput += ((sOutput == "") ? "" : "|") + Convert.ToString(drOutput[dcOutput]);
}
}
I am able to merge all columns in one String.
But how to replace character with another in store it in Same string as of "sOutput"
.
In foreach loop you can modify the row by accessing against the column index ("Comments") and use string.Replace to replace "*"
with "\n"
foreach (DataRow drOutput in dtOutput.Rows)
{
drOutput["Comments"] = drOutPut["Comments"].ToString().Replace('*','\n');
//your remaining code
}
foreach (DataRow row in dt.Rows)
row.SetField<string>("Comment",
row.Field<string>("Comment").Replace("*", @"\n"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With