Link to home
Create AccountLog in
Avatar of o0JoeCool0o1

asked on

Cannot Detect Carriage Return

Hi I am reading a string into a javascript variable that gets set to the innerHTML of a web element.

As such I am trying to write a function to replace all quotes apostrophes and Line breaks as writable values into a javascript string.

I have successfully replaced the quotes and apostrophes but the new lines are not working

if I use javascript and do this strReplace = strReplace.replace( /\r?\n/g, "<br />")
on the client it works

but I want to do this server side before passing the string back to the client

here is my procedure that loops through the data in my dataset and tries to replace all new lines or carriage returns. However none of these are replacing the carriage return as if it does not exist. however it does most certainly exist as it is breaking the code on the client with an unterminated string error from the new line.

also if I run my javascript command on it the lien breaks are detected and replaced with <br>

I just need this to work server side before passing it to the javascript

Private Sub makeWebSafe(ByRef dsWebSafe As DataSet)

        For Each datar As DataRow In dsWebSafe.Tables(0).Rows
            For Each col As DataColumn In dsWebSafe.Tables(0).Columns
                If col.DataType Is GetType(String) Then
                    If datar(col.Ordinal) <> "" Then
                        datar(col.Ordinal) = Replace(datar(col.Ordinal), Chr(34), "\" & Chr(34))
                        datar(col.Ordinal) = Replace(datar(col.Ordinal), "'", "\'")
                        datar(col.Ordinal) = Replace(datar(col.Ordinal), vbCrLf, "<br>")
                        datar(col.Ordinal) = Replace(datar(col.Ordinal), Chr(10) + Chr(13), "<br>")
                        datar(col.Ordinal) = Replace(datar(col.Ordinal), Chr(10) + Chr(12), "<br>")
                        datar(col.Ordinal) = Replace(datar(col.Ordinal), ControlChars.Cr, "<br>")
                        datar(col.Ordinal) = Replace(datar(col.Ordinal), ControlChars.NewLine, "<br>")

                    End If
                End If
    End Sub
Avatar of chapmandew
Flag of United States of America image

Look for CHAR(13) as well....
Sorry, you are....I missed it.
Avatar of o0JoeCool0o1

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account