replace <br> with NL

T

tshad

How do I go about this?

I used to know this, but can't find VB.net replace that does this.

Something like

string.replace("<br>",NL)

Thanks,

Tom
 
K

Karl Seguin

dim str as string = "hello<br>world"

dim newString as string = str.Replace("<br>", System.Environment.NewLine)

or you could use VbCrLf....I prefer Environment.NewLine

Karl
 
S

Steve C. Orr [MVP, MCSD]

Is this what you're looking for?
MyString = MyString.Replace("<br>",vbcrlf)
 
T

tshad

Steve C. Orr said:
Is this what you're looking for?
MyString = MyString.Replace("<br>",vbcrlf)

Actually, both were what I was looking for, but it doesn't work for my
mailto tag.

I am trying to send text that has line breaks in them in body of the
message:

For example:

I set a variable msg = " <a href='mailto:[email protected]?subject=Re:
Interview&body=this is<br><br>a test'>Email Me</a>"

This works fine as far as when my email program comes up but in the body I
get:

this is<br><br>a test

If I do a msg.replace("<br>",vbCrLf) or
msg.replace("<br>",System.Environment.NewLine), I get:

this isatest

I never get the line break.

What am I missing?

Thanks,

Tom
 
T

Tom wilson

Weird. Perhaps its expecting one or the other but not both. Try
replacing it with vbCR only or vbLf only.


Steve C. Orr said:
Is this what you're looking for?
MyString = MyString.Replace("<br>",vbcrlf)

Actually, both were what I was looking for, but it doesn't work for my
mailto tag.

I am trying to send text that has line breaks in them in body of the
message:

For example:

I set a variable msg = " <a href='mailto:[email protected]?subject=Re:
Interview&body=this is<br><br>a test'>Email Me</a>"

This works fine as far as when my email program comes up but in the body I
get:

this is<br><br>a test

If I do a msg.replace("<br>",vbCrLf) or
msg.replace("<br>",System.Environment.NewLine), I get:

this isatest

I never get the line break.

What am I missing?

Thanks,

Tom
 
T

tshad

Tom wilson said:
Weird. Perhaps its expecting one or the other but not both. Try
replacing it with vbCR only or vbLf only.

I wouldn't think so as if one or the other worked, so would vbCrLf and
System.Environment.NewLine.

I am sending the email from Outlook, so I would have assumed that the <br>
would work.

Tom
 
G

Guest

I always do this in code via the sendmail object, but if you do it this way
are you sure the default is to accept html (vs. text), or do you need to call
that out somewhere?

tshad said:
Steve C. Orr said:
Is this what you're looking for?
MyString = MyString.Replace("<br>",vbcrlf)

Actually, both were what I was looking for, but it doesn't work for my
mailto tag.

I am trying to send text that has line breaks in them in body of the
message:

For example:

I set a variable msg = " <a href='mailto:[email protected]?subject=Re:
Interview&body=this is<br><br>a test'>Email Me</a>"

This works fine as far as when my email program comes up but in the body I
get:

this is<br><br>a test

If I do a msg.replace("<br>",vbCrLf) or
msg.replace("<br>",System.Environment.NewLine), I get:

this isatest

I never get the line break.

What am I missing?

Thanks,

Tom
 
J

Juan T. Llibre

re:
For example:
I set a variable msg = " <a href='mailto:[email protected]?subject=Re:
Interview&body=this is<br><br>a test'>Email Me</a>"

That is a text link.
You can't use HTML in text links.



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

tshad said:
Steve C. Orr said:
Is this what you're looking for?
MyString = MyString.Replace("<br>",vbcrlf)

Actually, both were what I was looking for, but it doesn't work for my
mailto tag.

I am trying to send text that has line breaks in them in body of the
message:

For example:

I set a variable msg = " <a href='mailto:[email protected]?subject=Re:
Interview&body=this is<br><br>a test'>Email Me</a>"

This works fine as far as when my email program comes up but in the body I
get:

this is<br><br>a test

If I do a msg.replace("<br>",vbCrLf) or
msg.replace("<br>",System.Environment.NewLine), I get:

this isatest

I never get the line break.

What am I missing?

Thanks,

Tom
 
T

tshad

Juan T. Llibre said:
re:

That is a text link.
You can't use HTML in text links.

But the problem is I can't seem to use linefeeds,either.

Here is the program that sends 2 <br>s and it shows on the email we are
trying to send:
*********************************************************************
<%@ Page Language="VB" trace="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ Import Namespace="System.Web.Mail" %>
<script runat="server">
sub sendEmail(sender As Object, e As System.EventArgs )

Dim mailTo as String = "Email: <a
href=""mailto:[email protected]?subject=Our test&body=This is line
1<br><br>This is line2 "">to Tom</a>"

Dim Message As New MailMessage()
message.From = "(e-mail address removed)"
message.To = "(e-mail address removed)"
message.Subject = "Email test"
message.Body = mailTo
trace.warn("mailto = " & mailto)
message.Body = mailTo
message.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "localhost"
smtpMail.Send(message)
end sub
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form runat="server">
Send Email: <asp:Button ID="btnEmail" Text="Send" OnClick="SendEMail"
runat="server" />
</form>
</body>
</html>
**********************************************************************
When I press the link my email program comes up with:

This is line 1<br><br>This is line2

If I change the program to change the <br><br> to vbCrLf, I get the
following program:
********************************************************************
<%@ Page Language="VB" trace="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ Import Namespace="System.Web.Mail" %>
<script runat="server">
sub sendEmail(sender As Object, e As System.EventArgs )

Dim mailTo as String = "Email: <a
href=""mailto:[email protected]?subject=Our test&body=This is line
1<br><br>This is line2 "">to Tom</a>"

Dim Message As New MailMessage()
message.From = "(e-mail address removed)"
message.To = "(e-mail address removed)"
message.Subject = "Email test"
message.Body = mailTo

mailto = mailTo.replace("<br>",vbCrLf)

trace.warn("mailto = " & mailto)
message.Body = mailTo
message.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "localhost"
smtpMail.Send(message)
end sub
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form runat="server">
Send Email: <asp:Button ID="btnEmail" Text="Send" OnClick="SendEMail"
runat="server" />
</form>
</body>
</html>
*********************************************************************

If you look at the web page the mailto line is (notice that it skips 2
lines - so the CRLF seems to be there:
**********************************************************************
<a href="mailto:[email protected]?subject=Our test&body=This is line 1

This is line2 ">to Tom</a><BR>
*********************************************************************

But when I press the buttom the email program comes up and this is
displaying:

This is line 1This is line2

It seems to have stripped out the CRLFs.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top