简体   繁体   English

如何从textarea获取纯HTML

[英]How to get plain html from textarea

I want to get data from textbox in plain HTML ie if i write Hello World then it should return 我想从文本框中以纯HTML格式获取数据,即如果我写Hello World,那么它应该返回

Hello World

. I dont want to use HtmlEditor can i get plain html using textArea? 我不想使用HtmlEditor,可以使用textArea获得纯HTML吗?

http://www.dotnetperls.com/encode-html-string http://www.dotnetperls.com/encode-html-string

If you really need the   如果您确实需要  you can always string-replace spaces 你总是可以用字符串替换空格

You're probably going to need to transform the text manually (with string.Replace() or something similar) to accomplish this. 您可能需要手动转换文本(使用string.Replace()或类似方法)才能完成此操作。 Consider, for example, the "enter" and "space" tags you're looking for. 例如,考虑您要查找的“ enter”和“ space”标签。 If the user enters this as plain text (such as in a TextArea ): 如果用户以纯文本形式输入此内容(例如在TextArea ):

Hello World
Another line

Then that's precisely the value that's in the TextArea . 然后,这正是TextArea的值。 The user didn't enter this: 用户未输入以下内容:

Hello&nbsp;World<br />Another&nbsp;line

That's an entirely different string value. 那是一个完全不同的字符串值。 A WYSIWYG HTML editing control (and there are many for ASP.NET) would do some of the text transforms for you. 一个WYSIWYG HTML编辑控件(ASP.NET中有许多控件)将为您完成一些文本转换。 At least it would probably convert the carriage returns into break tags for you. 至少它将为您将回车符转换为中断标签。

But I doubt it would convert every space into a non-breaking space, since that's a very different value than what was entered. 但是我怀疑是否会将每个空间转换成一个不间断的空间,因为这与输入的值有很大不同。 You'll likely have to do that yourself. 您可能必须自己做。 (And be aware that converting all spaces into non-breaking spaces might not render the output like you expect. Look forward to a lot of horizontal scrolling.) (请注意,将所有空格转换为不间断空格可能不会像预期的那样呈现输出。期待进行大量的水平滚动。)

HTML isn't a translation of text into another medium, it's markup that's included in the text. HTML并不是将文本翻译成另一种媒介,而是包含在文本中的标记。 Both of my examples above are perfectly valid HTML. 我上面的两个示例都是完全有效的HTML。 One of them just doesn't include any markup tags. 其中之一只是不包含任何标记标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM