I need to make a script that takes some rich text (html text) and transform it to regular text. What I want to do is replace all <br>
tags with newline. I tried to do this with replace function:
set @rich_text_to_modify = replace(@rich_text_to_modify,'<br>', CHAR(13)+CHAR(10))
The
tags get removed but newlines are not inserted. Any idea what I am doing wrong?
You just concatenate the string and insert a CHAR(13) where you want your line break. This prints out the following: This is line 1. This is line 2.
First of all, What is nvarchar(n)? Variable-length Unicode string data. n defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB).
Background. The "N" prefix stands for National Language in the SQL-92 standard, and is used for representing Unicode characters.
The problem is your setting on SSMS, not that the data doesn't have a line break.
Go to: Tools -> Options -> Query Results -> SQL Server -> Results to Grid -> Retain CR/LF on copy or Save
and make sure the option is ticked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With