C # convert line breaks and spaces in the text box

Source: Internet
Author: User

This is actually what I found from the hard disk. It's old '''

In C #, when we input data in the text box (textbox), we can wrap the line (multiline text box), or enter a space in the multilin text box. However, when we read the data in the text box, we can use a space to display the data in another text box or directly use response. when the Write statement is displayed, we cannot display the line breaks and spaces as expected. The line breaks and spaces (the same applies to multiple spaces) are displayed with one space. Therefore, we need a method that can convert spaces and line breaks:
In C #, the line feed is represented by "\ r \ n". The Unicode codes of \ r and \ n are respectively 13 and 10, indicating that the Unicode codes of spaces are 32.

1. line feed conversion: (there are three types)

1 StringNewline=Textbox1.text. Replace ("\ X0d \ x0a","<Br/>");
2 StringNewline=Textbox1.text. Replace ("\ R \ n","<Br/>");
3 StringNewline=Textbox1.text. Replace (char. convertfromutf32 (13) Char. convertfromutf32 (10),"<Br/>");//<Br/> it is my habit or can be written <br>

2. space conversion: (2 types)

1 StringNewline=Textbox1.text. Replace ("\ X20","& Nbsp;");
2 StringNewline=Textbox1.text. Replace (char. convertfromutf32 (32),"& Nbsp;");

If you have the same habits as me and like to use <br/>: If you like the same, if the line and space must be converted, please first convert the space and then convert the line feed, otherwise, the line feed cannot be displayed. In my opinion, the space conversion converts the line feed to the space in <br personal display space/>.
For example:

Label1.text=(Textbox1.text. Replace (char. convertfromutf32 (32),"& Nbsp;"). Replace (char. convertfromutf32 (13) Char. convertfromutf32 (10),"<Br/> convertfromutf textbox replac;");

Or

 
Label1.text=(Textbox1.text. Replace (char. convertfromutf32 (13) Char. convertfromutf32 (10),"<Br>"). Replace (char. convertfromutf32 (32),"& Nbspconvertfromutf textbox replac;"));

Related Article

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.