如何将文本文件中的网址和电子邮件转换为HTML? [英] How to convert urls and emails in text file to html?
问题描述
大家好,
在我的程序中,我将文本文件(main.txt)的内容加载到名为''消息的
字符串中''。
我需要的是将此字符串中的所有网址和电子邮件转换为HTML格式。
这就是我所做的转换很难返回到< br>'并且它工作正常:
sws.WriteLine(message .Replace(Chr(13),< br>))
如此简单的回报很容易,但如果是网址和电子邮件怎么办?
因此,如果是url,它应该更改www.test.com。到< a
href =" http://www.test.com"> www.test.com< / a>"如果是电子邮件,
应该改变类似te ** @ test.com的内容。到< a
href =" mailto:te ** @ test.com"> te ** @ test.com< / a>"
>
有人可以帮帮我吗?
马丁
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
推荐答案
Martin ,
这是urlencode。
例如这个在
sTo = UrlEncode(sTo)
http://msdn.microsoft.com/library/de...ncodetopic.asp
我希望这有帮助,
Cor
" MARTIN LANNY" <毫安********** @ gmail.com> schreef in bericht
news:11 ********************** @ z14g2000cwz.googlegr oups.com ...
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...
大家好,
在我的程序中,我将文本文件(main.txt)的内容加载到名为消息的
字符串中。
我需要的是将此字符串中的所有网址和电子邮件转换为html。
这就是我将硬回车转换为< br>'并且工作正常的方法:
Dim sws As New IO.StreamWriter(pathtosave)
sws.WriteLine(message.Replace(Chr(13),"< br>"))
如此简单的回报很容易,但如果是网址和电子邮件怎么办?
那么,如果是网址,它应该改变www.test.com。到< a
href =" http://www.test.com"> www.test.com< / a>"如果是电子邮件,
应该改变类似te ** @ test.com的内容。 to< a
href =" mailto:te ** @ test.com"> te ** @ test.com< / a>"
有人可以帮忙吗?我出去了?
Martin
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
" MARTIN LANNY" <毫安********** @ gmail.com> schrieb:
"MARTIN LANNY" <ma**********@gmail.com> schrieb:
我需要的是将此字符串中的所有网址和电子邮件转换为html。
这就是我将硬回车转换为< br>''所做的s并且它工作正常:
Dim sws As New IO.StreamWriter(pathtosave)
sws.WriteLine(message.Replace(Chr(13),"< br>") )
如此简单的回报很容易,但如果是网址和电子邮件怎么办呢?
那么,如果是url它应该更改www.test .COM"到< a
href =" http://www.test.com"> www.test.com< / a>"如果是电子邮件,
应该改变类似te ** @ test.com的内容。 to< a
href =" mailto:te ** @ test.com"> te ** @ test.com< / a>"
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>"
>
我认为你必须自己实现代码将URL和
地址转换为超链接。如果你正在大量处理HTML,我建议你看一下''HttpUtility''类,它提供了编码URL和文本的方法。
编码URL和文本。
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://classicvb.org/petition/>
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/>
它不会让我用它。
我补充说:
Imports System.Web
....
..
Dim finalbody As String
finalbody = System.Web.HttpUtility.htmlencode(message)
但是" ; System.Web.htmlencode"下划线说htmlencode不是
a system.web的成员。
我也试过:finalbody = HttpUtility.htmlencode(message),但那是
相同。
为什么我不能用它?
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?
这篇关于如何将文本文件中的网址和电子邮件转换为HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!