M Mike P Feb 9, 2007 #1 How do you remove all chars such as carriage return and new line from a particular field for all records in a dataset?
How do you remove all chars such as carriage return and new line from a particular field for all records in a dataset?
M Mike P Feb 9, 2007 #2 Found the answer : foreach(DataRow dr in ds.Tables["LeadDetails"].Rows) { dr["Activity"] = dr["Activity"].ToString().Replace("\r", ""); dr["Activity"] = dr["Activity"].ToString().Replace("\n", ""); dr["Activity"] = dr["Activity"].ToString().Replace("\t", ""); }
Found the answer : foreach(DataRow dr in ds.Tables["LeadDetails"].Rows) { dr["Activity"] = dr["Activity"].ToString().Replace("\r", ""); dr["Activity"] = dr["Activity"].ToString().Replace("\n", ""); dr["Activity"] = dr["Activity"].ToString().Replace("\t", ""); }
? =?ISO-8859-1?Q?G=F6ran_Andersson?= Feb 10, 2007 #3 Mike said: Found the answer : foreach(DataRow dr in ds.Tables["LeadDetails"].Rows) { dr["Activity"] = dr["Activity"].ToString().Replace("\r", ""); dr["Activity"] = dr["Activity"].ToString().Replace("\n", ""); dr["Activity"] = dr["Activity"].ToString().Replace("\t", ""); } Click to expand... You do a lot of indexing and converting for no reason. You don't have to put the value back for each operation. foreach(DataRow dr in ds.Tables["LeadDetails"].Rows) { dr["Activity"] = ((string)dr["Activity"]).Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty); } or using the Regex class: foreach(DataRow dr in ds.Tables["LeadDetails"].Rows) { Regex.Replace((string)dr["Activity"], "[\\r\\n\\t]", string.Empty); }
Mike said: Found the answer : foreach(DataRow dr in ds.Tables["LeadDetails"].Rows) { dr["Activity"] = dr["Activity"].ToString().Replace("\r", ""); dr["Activity"] = dr["Activity"].ToString().Replace("\n", ""); dr["Activity"] = dr["Activity"].ToString().Replace("\t", ""); } Click to expand... You do a lot of indexing and converting for no reason. You don't have to put the value back for each operation. foreach(DataRow dr in ds.Tables["LeadDetails"].Rows) { dr["Activity"] = ((string)dr["Activity"]).Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty); } or using the Regex class: foreach(DataRow dr in ds.Tables["LeadDetails"].Rows) { Regex.Replace((string)dr["Activity"], "[\\r\\n\\t]", string.Empty); }