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

Looping through DataTable, replacing specific chars with CRLF

Status
Not open for further replies.

sbushway

Programmer
Jan 27, 2003
58
US
Hi,
I've got a DataTable and one of the columns (named 'ReasonForChange') in the DataTable may contain two right square brackets (]]). (I need to store carriage-return line-feeds as two right square brackets since the program that reads the data from the database chokes if it encounters a CRLF).

My problem is this: when I loop through my DataTable, I'm attempting to replace all instances of the brackets with a
Chr(13)+Chr(10). What happens is that instead of replacing it with that, it's just inserting spaces.

Here's my loop:

Code:
For Each dsRow in dsLogOfChanges.Tables("Log").Rows
   If(InStr(dsRow.Item("ReasonForChange").ToString, "]]") <> 0) Then
      dsRow.Item("ReasonForChange") = Replace(dsRow.Item("ReasonForChange"), "]]", Chr(13)+Chr(10))
   End If
Next

For example, one of the ReasonForChange fields could look like this in the database:
Address changed temporarily.]]Will return next month.

I'd like for it to be outputted in my DataGrid the same way that the user inputted it - like this:
Address changed temporarily.
Will return next month.

Except it ends up looking like this:
Address chaned temporarily. Will return next month.

Can anyone tell me what I'm doing wrong?

Thanks in advance,
Suzanne
 
I found the answer - instead of Chr(13)+Chr(10), someone suggested that I use "<br>" and that worked like a charm.
 
<br>"

so you were asking an asp.net question.
next time try the asp.net forum.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top