A program written in C # to delete a carriage return, newline, tab, and space in a string

Source: Internet
Author: User

When using the Cajviewer (I used the version 7.2.0 build 111) to consult the literature, the text is copied in Notepad resulting in multiple line breaks, as shown in:

There is no doubt that manually deleting the carriage return (\ n), line break (\ r), tab (\ t), and whitespace are deleted, which is very time-consuming and laborious. About one months ago, I wrote a very simple gadget in C # to solve this problem, and today I write down the code of the tool to make it easier to use later.

Program Interface


This program's window is set to always in the front, will be cajviewer in the "Select text" status selected text, press CTRL + C copy, press CTRL + V paste in the program text editing interface, click the "Convert" button, the program will automatically delete the carriage return, line breaks, tabs, spaces four characters, click "Copy "You can copy the newly generated text directly to the Clipboard and click" Reset "to empty the text editing interface. For ease of use, I also set the shortcut keys (alt+z, Alt+x, alt+c) for these three buttons, and then click to complete a set of combo! copied from Cajviewer from left to right.

Program Interface:

Program code: FormMain.cs

using system;using system.collections.generic;using system.componentmodel;using  system.data;using system.drawing;using system.linq;using system.text;using  system.threading.tasks;using system.windows.forms;namespace returnkiller{     public partial class formmain : form    {         public formmain ()         {             initializecomponent ();         }        private void btntrans_click (object sender, eventargs e)         {             string strTemp = txtText.Text;          &nBsp;  strtemp = strtemp.replace ("\ r",  "");             strtemp = strtemp.replace ("\ n",  "");             strtemp = strtemp.replace ("\ T",  "");             strtemp = strtemp.replace (" " ,  "");            txttext.text =  strtemp;        }         Private void btncopy_click (object sender, eventargs e)          {            clipboard.clear ();             if  (!string. Isnullorwhitespace (txttext.text))             {                 clipboard.settext (Txttext.text);                 console.beep (10000, 5);             }        }         private void btnreset_click (object sender,  Eventargs e)         {             txtText.Text =  "";         }     }}

Designer Code:

namespace returnkiller{    partial class formmain    {         /// <summary>         ///  Required designer variables.         /// </summary>         private System.ComponentModel.IContainer components = null;         /// <summary>        ///   Clean up all the resources that are in use.         /// </summary>         /// <param name= "disposing" > If a managed resource should be released,  true; otherwise  false. </param>        protected override void dispose ( bool disposing) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;{&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;      if  (disposing &&  (components != null) )             {                 components. Dispose ();            }             base. Dispose (disposing);        }          #region  Windows  form Designer generated code         /// <summary >        ///  Designer support Required methods  -  do not          ///  Modify the contents of this method using the Code editor.         /// </summary>         private void initializecomponent ()         {             this.panel2 = new system.windows.forms.panel ();             this.label1 = new system.windows.forms.label ();             this.btnReset = new  System.Windows.Forms.Button ();             This.btntrans = new system.windows.forms.button ();             this.groupbox1 = new system.windows.forms.groupbox ();             this.txtText = new  System.Windows.Forms.TextBox ();             This.btncopy = new system.windows.forms.button ();Nbsp;           this.panel2.suspendlayout ();             this.groupbox1.suspendlayout ();             this. SuspendLayout ();            //              // panel2             //              this.panel2.controls.add (this.btncopy);             this.panel2.controls.add (THIS.LABEL1);             this.panel2.controls.add (This.btnreset);             this.panel2.controls.add (This.btntrans);             this.panel2.dock =  system.windows.forms.dockstyle.bottom;             This.panel2.location = new system.drawing.point (0, 233);             this.panel2.Name =  "Panel2";             this.panel2.size = new system.drawing.size (478,  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;THIS.PANEL2.TABINDEX&NBSP;=&NBSP;1); ;            //              // label1             //              This.label1.autosize = true;            this.label1.location = new  System.Drawing.Point (301, 9);             this.label1.name =  "Label1";             This.label1.size = new system.drawing.size (167, 12);             this.label1.TabIndex = 2;             this.label1.Text =  "tsybius  made in  2015 year May 3";             //              // btnReset             //              This.btnreset.location = new syStem. Drawing.point (169, 4);             this.btnreset.name =  "Btnreset";             this.btnreset.size = new system.drawing.size (75, 23);             this.btnReset.TabIndex = 1;             this.btnReset.Text =  Reset (&c);             this.btnReset.UseVisualStyleBackColor = true;             this.btnReset.Click += new  System.EventHandler (This.btnreset_click);             //             // btnTrans             //              this.btntrans.location = new system.drawing.point (9, 4);             this.btnTrans.Name =  "Btntrans";             this.btnTrans.Size = new  System.Drawing.Size (75, 23);             this.btntrans.tabindex = 0;             this.btntrans.text =  "Convert (&z)";             this.btnTrans.UseVisualStyleBackColor = true;             this.btntrans.click += new system.eventhandler (This.btnTrans_Click);             //              // groupBox1            //              this.groupbox1.controls.add (This.txtText);             this.groupBox1.Dock =  system.windows.forms.dockstyle.fill;             This.groupbox1.location = new system.drawing.point (0, 0);             this.groupBox1.Name =  "GroupBox1";             this.groupbox1.size = new system.drawing.size ( 478, 233);             this.groupbox1.tabindex  = 2;            this.groupbox1.tabstop = false;             this.groupBox1.Text =  "Enter text here";             //              // txtText             //              this.txttext.dock = system.windows.forms.dockstyle.fill;             this.txttext.location = new system.drawing.point (3,&NBSP;17);             this.txtText.Multiline =  true;            this.txttext.name =  " Txttext ";             this.txttext.scrollbars =  system.windows.forms.scrollbars.vertical;             this.txttext.size = new system.drawing.size (472, 213);             this.txtText.TabIndex = 0;             //              // btnCopy            //              this.btncopy.location = new  system.drawing.point (89, 4);             this.btnCopy.Name =  "Btncopy";             this.btncopy.size = new system.draWing. Size (75, 23);             this.btncopy.tabindex = 3;             this.btncopy.text =  "Copy (&x)";             this.btnCopy.UseVisualStyleBackColor = true;             this.btncopy.click += new system.eventhandler (This.btnCopy_Click);             //              // FormMain             //             this. Autoscaledimensions = new system.drawing.sizef (6f, 12f);             thIs. autoscalemode = system.windows.forms.autoscalemode.font;             this. Clientsize = new system.drawing.size (478, 264);             this. Controls.Add (this.groupbox1);             this. Controls.Add (THIS.PANEL2);             this. formborderstyle = system.windows.forms.formborderstyle.fixed3d;             this. Maximizebox = false;            this. name =  "FormMain";             this. Showicon = false;            this. Startposition = system.wiNdows. forms.formstartposition.centerscreen;             This. text =  "Returnkiller";             this. topmost = true;             This.panel2.ResumeLayout (False);             This.panel2.PerformLayout ();             This.groupBox1.ResumeLayout (False);             This.groupBox1.PerformLayout ();             this. ResumeLayout (False);        }          #endregion         private system.windows.forms.panel  panel2;        private system.windows.forms.button btnreset;         private System.Windows.Forms.Button btnTrans;         private System.Windows.Forms.GroupBox groupBox1;         private System.Windows.Forms.TextBox txtText;         private System.Windows.Forms.Label label1;         private system.windows.forms.button btncopy;    }}


Attached: Engineering Documents (Baidu network disk) http://pan.baidu.com/s/1sj3aI7r

END

A program written in C # to delete a carriage return, newline, tab, and space in a string

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.