473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to convert urls and emails in text file to html?

Hi All,

In my program I am loading the content of a text file (main.txt) into a
string called 'message'.

What I need is to convert all urls and emails in this string into html.

This is what I did to convert hard returns to <br>'s and it works fine:

Dim sws As New IO.StreamWriter(pathtosave)
sws.WriteLine(message.Replace(Chr(13), "<br>"))

So hard returns were easy, but how to do it in case of urls and emails?

So, that in case of url it should change "www.test.com" to "<a
href="http://www.test.com">www.test.com</a>" and in case of email it
should change something like "te**@test.com" to "<a
href="mailto:te**@test.com">te**@test.com</a>"

Can someone help me out?

Martin

Nov 21 '05 #1
12 1623
Martin,

It is the urlencode.

By example this in the to
sTo = UrlEncode (sTo)

http://msdn.microsoft.com/library/de...ncodetopic.asp

I hope this helps,

Cor

"MARTIN LANNY" <ma**********@gmail.com> schreef in bericht
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi All,

In my program I am loading the content of a text file (main.txt) into a
string called 'message'.

What I need is to convert all urls and emails in this string into html.

This is what I did to convert hard returns to <br>'s and it works fine:

Dim sws As New IO.StreamWriter(pathtosave)
sws.WriteLine(message.Replace(Chr(13), "<br>"))

So hard returns were easy, but how to do it in case of urls and emails?

So, that in case of url it should change "www.test.com" to "<a
href="http://www.test.com">www.test.com</a>" and in case of email it
should change something like "te**@test.com" to "<a
href="mailto:te**@test.com">te**@test.com</a>"

Can someone help me out?

Martin

Nov 21 '05 #2
"MARTIN LANNY" <ma**********@gmail.com> schrieb:
What I need is to convert all urls and emails in this string into html.

This is what I did to convert hard returns to <br>'s and it works fine:

Dim sws As New IO.StreamWriter(pathtosave)
sws.WriteLine(message.Replace(Chr(13), "<br>"))

So hard returns were easy, but how to do it in case of urls and emails?

So, that in case of url it should change "www.test.com" to "<a
href="http://www.test.com">www.test.com</a>" and in case of email it
should change something like "te**@test.com" to "<a
href="mailto:te**@test.com">te**@test.com</a>"


I think that you'll have to implement the code to convert the URLs and
addresses to hyperlinks yourself. If you are dealing heavily with HTML, I
suggest to take a look at the 'HttpUtility' class which provides methods for
encoding URLs and text.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
Hi, it won't let me use it.

I added:

Imports System.Web
....
..
Dim finalbody As String
finalbody = System.Web.HttpUtility.htmlencode(message)
but "System.Web.htmlencode" is underlined saying that htmlencode is not
a member of system.web.

I also tried: finalbody = HttpUtility.htmlencode(message), but that is
the same.

Why can't I use it?

Nov 21 '05 #4
ok, I figured how to make it work... let me test it now...

Nov 21 '05 #5
"MARTIN LANNY" <ma**********@gmail.com> schrieb:
Hi, it won't let me use it.

I added:

Imports System.Web


Make sure your project contains a reference to "System.Web.dll".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #6
Yeah thanks...I just realized...

Nov 21 '05 #7
It doesn't work:

dim message as string = "jo*@gnut.com wrote in message"
Dim finalbody As String
finalbody = System.Web.HttpUtility.HtmlEncode(message)
return finalbody

This is what it returns:
"&lt;jo*@gnut.com&gt; wrote in message"

It should return this:
"<a href="mailto:jo*@gnut.com">jo*@gnut.com</a> wrote in message"

Any other ideas?

Nov 21 '05 #8
"MARTIN LANNY" <ma**********@gmail.com> schrieb:
dim message as string = "jo*@gnut.com wrote in message"
Dim finalbody As String
finalbody = System.Web.HttpUtility.HtmlEncode(message)
return finalbody

This is what it returns:
"&lt;jo*@gnut.com&gt; wrote in message"

It should return this:
"<a href="mailto:jo*@gnut.com">jo*@gnut.com</a> wrote in message"


As I already said, you'll have to build the HTML code yourself.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #9
And I guess, that is what I needed a help with initialy.
I don't know how to convert text links to html coded links.
Maybe I wasn't very clear., but this System.Web.HttpUtility.HtmlEncode
didn't do any of what I asked for.

Nov 21 '05 #10
Is there maybe some regex to convert text links to html links?

Nov 21 '05 #11
"MARTIN LANNY" <ma**********@gmail.com> schrieb:
And I guess, that is what I needed a help with initialy.
I don't know how to convert text links to html coded links.
Maybe I wasn't very clear., but this System.Web.HttpUtility.HtmlEncode
didn't do any of what I asked for.


For example:

\\\
Private Function EMailAddressToHtml(ByVal Address As String) As String
Return _
"<a href=""mailto:" & HttpUtility.UrlEncode(Address) & """>" & _
HttpUtility.HtmlEncode(Address) & _
"</a>"
End Function
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #12
That is perfect examle, but if I feed my whole text to it, it won't do
anything.
I need some function to scan text for emails and urls and replace them
all.
Isn't regex.replace something I could use? And if yes, how?

Nov 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dan glenn | last post by:
I'm creating HTML emails from a PHP site and sending them out to an email list (just about 40 people so far are on this list). I've tested and confirmed that these emails work in yahoo.com's...
1
by: Ambuj | last post by:
Can anyone please let me know that how can I handle very long URLs in a text email? I'm writting a bulk email program in VB.Net which sends text emails. The problem is when I've a very long URL it...
7
by: David Shorthouse | last post by:
Hey folks, Is anyone aware of any sort of asp coding to deal with long URLs? I have a few asp that pull URLs from fields within a MS db, which then display on a width-limited table. Is there any...
4
by: Nicole | last post by:
Hello, Can anyone tell me or give me an online tool which can help me to convert php dynamic urls to html urls to make a google friendly site.I dont have apache server on my computer and I dont...
21
by: maya | last post by:
hi, I'm designing an HTML email for a client.. I know general guidelines (no CSS, no JavaScript... although I do use limited CSS, inside tags (as in <span style=".."we do this at work and it...
5
by: sck10 | last post by:
Hello, I am working on a new project where I need to: 1. open an email and then create an xml file from the email 2. open the xml file and parse the information. I would like to be able to do...
5
by: Jai | last post by:
Hi, I am in a problem of sending mass emails(newsletter) to my website members. Actually my problem is this: I want to send newsletter to my website members. But I had given a facility for...
3
by: Vlad | last post by:
Hi! My task: Take HTML -convert into plain text. Sub-task: 1. Find all urls within HTML (<a href="http://www.abc.com">More about baby bears</a>). 2. And convert them into plain text: More...
13
by: davjoh | last post by:
The following describes the problem I am having. Can anyone help? $send_to = "davjoh123@yahoo.com"; $send_to = "production@advisiongraphics.com"; $send_to =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.