简体   繁体   中英

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

Hello World

. I dont want to use HtmlEditor can i get plain html using textArea?

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. Consider, for example, the "enter" and "space" tags you're looking for. If the user enters this as plain text (such as in a TextArea ):

Hello World
Another line

Then that's precisely the value that's in the 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. 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. Both of my examples above are perfectly valid HTML. One of them just doesn't include any markup tags.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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