Code snippet of the day: Convert rich text into plain text.

Source: Internet
Author: User
When you copy from one program's document and paste in another program's document, you almost never want to keep the formatting. A simple example is when you copy from word or other document into the rich text control that. text uses on the new post page, you get a hunk of unwanted HTML around the pasted text. what a worry it is!
OK, maybe this program can help you out :)

Rich code Plain code
1  Using System; 2  Using System. Windows. forms; 3  Namespace Plainclipper { 4    Class Class1 {5 [Stathread] 6      Static   Void Main ( String [] ARGs ){ 7 Idataobject oldclip = clipboard. getdataobject (); 8       If (Oldclip! = Null ){ 9 Dataobject newclip = New Dataobject (); 10          Foreach ( String Format In Oldclip. getformats ()){11            If (Format! = "HTML format" ){ 12 Newclip. setdata (format, oldclip. getdata (Format )); 13 } 14 }15 Clipboard. setdataobject (newclip, True ); 16 } 17 } 18 } 19 }
 
Using system; using system. windows. forms; namespace plainclipper {class class1 {[stathread] Static void main (string [] ARGs) {idataobject oldclip = clipboard. getdataobject (); If (oldclip! = NULL) {dataobject newclip = new dataobject (); foreach (string format in oldclip. getformats () {If (format! = "HTML format") {newclip. setdata (format, oldclip. getdata (Format) ;}} clipboard. setdataobject (newclip, true );}}}}

See orginal article: The smallest useful program I 've ever written

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.