Guys, I'm trying to remove the whitespace in the middle of a string within a datagridview cell, i think i'm close with the below but it doesn't do anything?
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.IsNewRow) break;
object obj = row.Cells[8].Value;
{
string trim = Regex.Replace(Text, @"\s+", " ").Trim();
}
}
so i want the output in row.cells[8] to change from this: 123 456 to end up as this: 123456
Remove whitespace from middle of string in datagrid
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Mar 28, 2012, 12:48 AM EDT
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.IsNewRow) break;
object obj = row.Cells[8].Value;
if (obj != null) row.Cells[8].Value = Regex.Replace(obj.ToString(), @"\s+", "").Trim();
}
mike DelvottiRank #7,298 · 244 reputationPosted Mar 28, 2012, 1:06 AM EDT