Convert plain text string to HTML

  • Thread starter Thread starter Dennis
  • Start date Start date
D

Dennis

Is there anything built in to vb.net that will take a plain text string
and reformat it as HTML? What I mean is:

o replace newlines with <BR>
o replace " with &quot;
o etc.

I am using vb.net 2003.

Thanks,
 
Dennis said:
Is there anything built in to vb.net that will take a plain text string
and reformat it as HTML? What I mean is:

o replace newlines with <BR>
o replace " with &quot;
o etc.

I am using vb.net 2003.


The simplest way to do this is using 'Replace'. In addition check out
'HttpUtility.HtmlEncode'.
 
Is there anything built in to vb.net that will take a plain text string
and reformat it as HTML? What I mean is:

o replace newlines with <BR>
o replace " with &quot;
o etc.

I am using vb.net 2003.

Thanks,

For the <BR> you'll have to make do with the string.replace(). For the
other html entities like &quot; &gt; etc you can use the
HttpUtility.HTMLEncode() function
 
Just curious as to why replace with &quot, etc. I generate an HTML code
within VB from a database and save it as an HTM file. It displays fine in
internet explorer. Is there some problem if I were to send this page via
e-mail or something?
 
Dennis said:
Just curious as to why replace with &quot, etc. I generate an HTML code
within VB from a database and save it as an HTM file. It displays fine in
internet explorer. Is there some problem if I were to send this page via
e-mail or something?

There is generally no reason to use '&quot;' instead of the double quotation
mark character except if the encoding used to save the file does not contain
the character (which is very unlikely nowadays) or in attribute values
surrounded by double quotation marks.

Valid XHTML:

* '<img src="1.gif" alt="Bla &quot;Bla&quot; Bla"/>'
* '<img src="1.gif" alt='Bla "Bla" Bla'/>'

Invalid XHTML:

* '<img src="1.gif" alt="Bla "Bla" Bla"/>'

The same applies to '&apos;' vs. the single quotation mark character.
 
Cor Ligthert said:
In my idea is the double space still a problem
&nbsp

Which double space?

'&nbsp;' is not the same as " ". The first one is a non-breaking space
(thus '&nbsp;') which prevents insertion of soft line breaks.
 
Back
Top