How to convert the input text into HTML code into the database?

Source: Internet
Author: User
Tags chr

<summary>

Replace special characters in HTML

</summary>

<param name= "TheString" > Text that needs to be replaced. </param>

<returns> Replace the finished text. </returns>

public string HtmlEncode (string thestring)

{

Thestring=thestring.replace (">", "&gt;");

Thestring=thestring.replace ("<", "&lt;");

Thestring=thestring.replace ("", "&nbsp;");

Thestring=thestring.replace ("", "&nbsp;");

Thestring=thestring.replace ("/" "," &quot; ");

Thestring=thestring.replace ("/", "& #39;");

Thestring=thestring.replace ("n", "<br/>");

return thestring;

}

How to input a large section of text in the page text into the database format and read from the database to restore the format

Xiaomaoxia (a little bee flying in the Bushes) Grade: Knot Rate: 100% Landlord posted on: 2002-10-22 17:03:44
The format simply refers to carriage returns, blanks, etc.,
If a code is entered, it is executed when it is read out from the database and displayed. How to deal with.
It worked for me. [0] lost a brick [0] cited report management top reply number: 0-->

Xiaomaoxia (a little bee flying in the Bushes) rank: #1楼 Score: 0 reply to: 2002-10-22 17:16:21
My top
Useful to me [0] throw a brick [0] Quote report Management Top

Sanniko (Goose title mud) Grade: #2楼 Score: 10 reply to: 2002-10-22 17:18:27
First you want to make sure that the conversion of the characters such as ' <> return space is so that you can write to the database, and then the display will be converted to the corresponding switch.
Useful to me [0] throw a brick [0] Quote report Management Top

Xiaomaoxia (a little bee flying in the Bushes) rank: #3楼 Score: 0 reply to: 2002-10-22 17:22:51
Example
String test;
String test1;
Test=test. Replace ("", "&nbsp")
How to replace the carriage return ...
Useful to me [0] throw a brick [0] Quote report Management Top

Gangganghao (Ganggang) Grade: #4楼 Score: 10 reply to: 2002-10-22 17:24:11
If it is a multiline text box input ... Show in multiline text box ... Do not need to do the processing.
If it is not displayed in a multiline text box
Replace CHR &CHR (10) in Server.HTMLEncode (database content) with <br>
Replace Chr (32) &CHR with &nbsp;&nbsp; With replace

What code do you mean by code. of HTML.

Useful to me [0] throw a brick [0] Quote report Management Top

Thinkway (Thinkway) Grade: #5楼 Score: 10 reply to: 2002-10-22 17:50:16
Enter. Replace "n" with "<br>" on the line.
Useful to me [0] throw a brick [0] Quote report Management Top

Xiaomaoxia (a little bee flying in the Bushes) rank: #6楼 Score: 0 reply to: 2002-10-23 09:01:37
Gold near: <br> &nbsp&nbsp&nbsp Defangjun &nbsp Card Tunnel Bureau guilty of a fine &nbsp&nbsp&nbsp&nbsp military proliferation local officers , &nbsp labor Law import &nbsp
<br> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp& nbsp Card strike Law &nbsp Ah, dead hangar &nbsp.

This is what I saved in the database after I replaced it, read it out of the database and show it on the page:
Gold near: <br> &nbsp&nbsp&nbsp Defangjun &nbsp Card Tunnel Bureau guilty of a fine &nbsp&nbsp&nbsp&nbsp military proliferation local officers , &nbsp labor Law import &nbsp
<br> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp& nbsp Card strike Law &nbsp Ah, dead hangar &nbsp.

^_^, what should I do?
Useful to me [0] throw a brick [0] Quote report Management Top

Xiaomaoxia (a little bee flying in the Bushes) rank: #7楼 Score: 0 reply to: 2002-10-23 09:04:46
Add: The following is the panel,html code to display the content
<asp:panel id= "Panel1" runat= "server" font-names= "italics _gb2312" font-size= "Small" height= "175px" Wid Th= "750px" forecolor= "Black" horizontalalign= "left" > <%=forcontent%> <font face= "song Body" size= "3 "> </FONT> </asp:panel>

Forcontent is a content variable read from the database

Also, can you display the format in the page with a panel?

I've never done this before.
Useful to me [0] throw a brick [0] Quote report Management Top

Thinkway (Thinkway) Grade: #8楼 Score: 10 reply to: 2002-10-23 10:01:04
Do not replace it in the database, and replace it in the read data.
If you make two replacements, you'll be back soon.
Again, data is data, and if your data is to be displayed in Windows instead of on a Web page, it's not a mess.
Useful to me [0] throw a brick [0] Quote report Management Top

Thinkway (Thinkway) Grade: #9楼 Score: 30 Reply to: 2002-10-23 10:05:17
This could help you ...
CS function to translate text into HTML documents: Textparser.parser (string text, bool allow)

Using System;
Using System.Text;
Using System.IO;

Namespace Website.support
{
public class Textparser
{
Public Textparser ()
{
//
Todo:add constructor Logic here
//
}

method to parse Text into HTML
public string Parser (string text, bool allow)
{
Create a StringBuilder object from the string intput parameter
StringBuilder sb = new StringBuilder (text);
Replace all double white spaces and &nbsp;
Sb. Replace ("", "&nbsp;");
Check if HTML tags are not allowed
if (!allow)
{
Convert the brackets into HTML equivalents
Sb. Replace ("<", "&lt;");
Sb. Replace (">", "&gt;");
Convert the double quote
Sb. Replace ("/", "&quot;");
}
Create a StringReader from the processed string of the StringBuilder object
StringReader sr = new StringReader (sb. ToString ());
StringWriter SW = new StringWriter ();
Loop while next character exists
while (Sr. Peek () >-1)
{
Read a line from the string and store it to a temp variable
String &n

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.