Roberto Flores
Roberto Flores

Reputation: 789

Replace '<BR>' with ' ' in VB

Problem: I am trying to replace the carriage return with a space. So I have the following:

txt="This is a beautiful day!<BR>"
response.write(Replace(txt,"<BR>"," "))

And I would like the <BR> to be replaced with a space. The reason being is following the string, I would have text after the string. So like:

txt Blah Blah Easter Day!

I also tried the following:

<%Dim auth As String = "Reason"
Dim txt As String = " You may contact your provider for detailed information about your diagnosis or treatment. This could include the detailed codes and their meanings."
auth = auth.Replace("<BR>", " ")
Dim txt1 As String = auth + txt
Response.Write(txt1)
%>

The Reason is a field that contains text followed by a <BR>. I thought by using replace I could remove it without updating the field (which I do not want to do). Instead, what happens is the following:

Blah blah blah.
You may contact your provider....

How can I achieve:

Blah blah blah. You may contact your provider....

Any help would be appreciated.

Upvotes: 0

Views: 1618

Answers (2)

freginold
freginold

Reputation: 3956

Your function looks correct; it should be removing the <br>. However, there may also be a Visual Basic line break at the end of the text line. Try adding this function below your current replace function to remove that line break, if it exists:

auth = auth.Replace(VbCrLf, "")

For completeness's sake, you can also add these:

auth = auth.Replace(VbCr, "")
auth = auth.Replace(VbLf, "")

Upvotes: 1

Jason Bayldon
Jason Bayldon

Reputation: 1296

Am I missing something here?

    Dim txt = "This is a beautiful day!<BR>"
    txt = txt.Replace("<BR>", " ")
    MessageBox.Show(txt)

Upvotes: 0

Related Questions