Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove chars from field in dataset

Status
Not open for further replies.

arkadia93

Programmer
Oct 19, 2006
110
0
0
GB
How do you remove all chars such as carriage return and new line from a particular field for all records in a dataset?
 
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", "");
}
 
If you're going to be looping through a lot of records, I'd use constants for those string literals, use String.Empty for the zero-length strings, and use the StringBuilder class to do the replaces.

It could get you a noticeable performance increase.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top