stringbuilder help

A

Aaron

Dim sbRegX As New StringBuilder(HttpUtility.HtmlEncode(txtComments.Text))

sbRegX.Replace("&lt;a&gt;", "<a>")

sbRegX.Replace("&lt;/a&gt;", "")



How do I get the attributes of href and target to be encoded?
 
H

Herfried K. Wagner [MVP]

Aaron said:
Dim sbRegX As New StringBuilder(HttpUtility.HtmlEncode(txtComments.Text))
sbRegX.Replace("&lt;a&gt;", "<a>")
sbRegX.Replace("&lt;/a&gt;", "")

How do I get the attributes of href and target to be encoded?

Encoded as what?
 
A

Aaron

Herfried,

I have a text box that could have <a href="yahoo.com"
target="_new">yahoo</a>

With just
sbRegX.Replace("&lt;a&gt;", "<a>")
sbRegX.Replace("&lt;/a&gt;", ""</a>)

The output is
<a href="yahoo.com" target="_blank">Yahoo
and the data looks like this
&amp;lt;a href=&amp;quot;yahoo.com&amp;quot;
target=&amp;quot;_blank&amp;quot;&amp;gt;Yahoo&lt;/a&gt;,



I need it to look like http://www.yahoo.com with it in a new window.

TIA

Aaron
 
S

S. Justin Gengo [MCP]

Aaron,

You'll be looking for Server.HtmlEncode and Server.HtmlDecode. You may also
want to experiment (depending on all the uses of the input text) with
Sever.UrlEncode and Server.UrlDecode.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Aaron said:
Herfried,

I have a text box that could have <a href="yahoo.com"
target="_new">yahoo</a>

With just
sbRegX.Replace("&lt;a&gt;", "<a>")
sbRegX.Replace("&lt;/a&gt;", ""</a>)

The output is
<a href="yahoo.com" target="_blank">Yahoo
and the data looks like this
&amp;lt;a href=&amp;quot;yahoo.com&amp;quot;
target=&amp;quot;_blank&amp;quot;&amp;gt;Yahoo&lt;/a&gt;,



I need it to look like http://www.yahoo.com with it in a new window.

TIA

Aaron
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top