开发者

Format/Safe string for "title" attribute in anchor

I have a function that builds an anchor tag. The function recieves the开发者_运维百科 URL, Title as parameters. The problem is that sometime the text includes quotation marks and this results in a anchor tag generated with syntax errors.

Which is the best way to solve this problems? Is there any function that parses the text into a safe string, in this case, for the title attribute.

Otherwise I can check the string and strip all quotation marks, but I would like know if there is a better way to do this, e.g there might be some other characters that can crash my function as well.


Actually you want to use HttpUtility.HtmlAttributeEncode to encode your title attribute. The other encoders will do more work (and have different uses) whereas this one only escapes ", &, and < to generate a valid text for an attribute.

Example: This is a <"test"> & something else. becomes This is a &lt;&quot;Test&quot;> &amp; something else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜