Replace “\n” with “<BR\>”
There are lot of times we accept user input in a textarea or a multiline textbox and save it to a database. But while displaying the data from the database, you will find that the line breaks are not displayed properly, infact there will be no line breaks. We will need to convert all the new line characters (”\n” character) to “<BR/>” so that they are properly rendered in the browser. There seems to be quite a few ways to do it but the simplest method which always worked for me is as follows. Just pass the string to the the function and it will format the string properly so that the new line characters are replaced with “<Br/>” tags
Public Shared Function ConvertToBR(ByVal InputString As String) As String
Dim Pattern As String = "\n"
Dim Rgx As New Regex(Pattern)
Dim OutputString As String=Rgx.Replace(InputString, "<br/>")
Return OutputString
End Function