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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Better way to perform replacements?

Status
Not open for further replies.

logicalunatic

Programmer
Jan 19, 2004
84
US
I'm working on a project where some (ntext) in a MSSQL database is to be displayed on the web. I've been able to successfully replace all CRLF (VB-vbCrLf or C#-"\r\n") with Breaks but I'm wondering if there is a better way to do it. In ASP 3.0 I would just use...
Code:
Replace(x_string,vbCrLf,"<br />")
which is quite easy.

The way I've done it in .Net is...
Code:
//Replace1 the \r\n in t_comments with <br />
DataRow dr;
string x_comments;
for (int i=0 ; i < ds.Tables["t_reviews"].Rows.Count ; i++)
		{
			dr = ds.Tables["t_reviews"].Rows[i];
			x_comments = dr["t_comments"].ToString();
			dr["t_comments"] = x_comments.Replace("\r\n","<br />");
		}
//End Replace1
Could I have done this easier? Perhaps in the repeater?

Thanks in Advance...

LogicaLunatic
 
You could have used Environment.NewLine versus "\r\n".
I don't use SqlServer but I would have done the conversion in the db query in Oracle it would be REPLACE and from a google SqlServer's equivalent is STUFF.
Marty
 
That was a great suggestion and MSSQL does have a Replace function. Unfortunately Replace doesn't work on (ntext) field types and Stuff is used to insert a string into another string.

Thanks for the suggestion though!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top