HTMLen code HTMLde code [英] HTMLencode HTMLdecode

查看:286
本文介绍了HTMLen code HTMLde code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本区域,我想以存储用户的HTML格式的类似段落分隔符,编号列表中输入数据库中的文本。我使用HTMLen code和HTMLde code这一点。

I have a text area and I want to store the text entered by user in database with html formatting like paragraph break, numbered list. I am using HTMLencode and HTMLdecode for this.

我的code样品是这样的:

Sample of my code is like this:

string str1 = Server.HtmlEncode(TextBox1.Text);
Response.Write(Server.HtmlDecode(str1));

如果有2个段落用户输入的文本,STR1显示字符\段落的R \ñ\ r \ñ。但是当它写入到屏幕上,只需追加与第一第二段落。虽然我对其进行解码,为什么没有打印2款?

If user entered text with 2 paragraphs, str1 shows characters \r\n\r\n between paragraphs. but when it writes it to screen, just append 2nd paragraph with 1st. While I'm decoding it, why doesn't it print 2 paragraphs?

推荐答案

简单的解决办法是这样:

The simple solution would be to do:

string str1 = Server.HtmlEncode(TextBox1.Text).Replace("\r\n", "<br />");

这是假设你只关心获得正确的&LT; BR /&GT; 标签的地方。如果你想有一个真正的格式,你需要像Aaronaught图书馆建议。

This is assuming that you only care about getting the right <br /> tags in place. If you want a real formatter you will need a library like Aaronaught suggested.

这篇关于HTMLen code HTMLde code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆