That is really quite messy, and inefficient.
1) You don't need to use Regex - string.Replace is simpler.
2) Don't keep converting datatypes - it wastes time, and memory. (I assume "colon", "slash" etc. are
char
types)
3) Don't keep temporary values in array elements.
string strColon = colon.ToString();
string strBlank = Blank.ToString();
foreach (DataRow datarow in dv.Table.Rows)
{
foreach (DataColumn datacol in dv.Table.Columns)
{
string s = datarow[datacol].ToString();
s = s.Replace(comma, slash);
s = s.Replace(strColon, strBlank);
datarow[datacol] = s;
}
}
You don't need to store the temporary value in a named variable as I have, but it makes it easier to read.
This code (and yours for that matter) should work fine if you use the DataColumn as an index (as you currently do) or an integer index based on the number of rows / columns in the table. If it doesn't, you will have to give us a sample of the non-working code before we could comment. Edit your question to include the non-working version.