X01.TextProc: A small tool completed in two or three minutes. One goal is two or three.

Source: Internet
Author: User

X01.TextProc: A small tool completed in two or three minutes. One goal is two or three.

In work, if you encounter such a problem, you need to enter the product number in the Excel table, which is similar to 2134-1234-4456, into the program of the unit, the program only recognizes the input without '-' As 213412344456. A large number of clicks, which are time-consuming and labor-consuming. Therefore, converting, copying, and pasting not only improves the speed, but also prevents errors. In addition, because Excel tables are provided by others, this problem may occur repeatedly, so it is necessary to write a conversion tool.

Can I directly operate on Excel? The problem is "too short". Obviously, this is not necessary. My method is to copy and paste the item number column into notepad and save it as the temp.txt file. Now the problem is simplified to common text processing. Create a new WPF program. The content of MainWindow. xaml and MainWindow. xaml. cs is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?> <Window x: Class = "TextProc. mainWindow "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" Title = "Text Proc" Height = "380" Width = "500" WindowStartupLocation = "CenterScreen"> <StackPanel> <ScrollViewer Height = "300" VerticalScrollBarVisibility =" auto "> <TextBox Name =" txtContent "Margin =" 5 "/> </ScrollViewer> <StackPanel Orientation =" Horizontal "HorizontalAlignment =" Right "> <Button Name =" btnSelect "Content =" _ Select "/> <Button Name =" btnProcess "Content =" _ Process "/> </StackPanel> </Window>MainWindow. xaml/*** MainWindow. xaml. cs (c) 2015 by x01 * -------------------------------- */using System; using System. collections. generic; using System. IO; using System. text; using System. text. regularExpressions; using System. windows; using System. windows. controls; using System. windows. data; using System. windows. documents; using System. windows. input; using System. windows. media; using Microsoft. win32; names Pace TextProc {// <summary> // Interaction logic for Window1.xaml // </summary> public partial class MainWindow: Window {string _ path = null; openFileDialog _ dlg = new OpenFileDialog (); public MainWindow () {InitializeComponent (); _ dlg. filter = "*. txt | *. txt | *. * | *. * "; btnProcess. click + = delegate {if (string. isNullOrEmpty (_ path) return; var text = File. readAllText (_ path); text = ProcessText (Text); txtContent. Text = text; File. WriteAllText (_ path + ". proc", text); MessageBox. Show ("Process Text Success! ") ;}; BtnSelect. click + = delegate {_ dlg. showDialog (); _ path = _ dlg. fileName; txtContent. text = File. readAllText (_ path) ;};/// main text processing logic. Use line breaks for segmentation and only retain numbers. This can be adjusted based on actual conditions. Private string ProcessText (string text) {string [] arr = text. split ('\ n'); List <string> result = new List <string> (); foreach (var a in arr) {char [] cs =. toCharArray (); string s = string. empty; for (int I = 0; I <cs. length; I ++) {if (cs [I] <'0' | cs [I]> '9') continue; s + = cs [I]. toString ();} result. add (s) ;}string str = string. empty; foreach (var r in result) {str + = r + "\ n";} return str ;}}}MainWindow. cs

Because it is written in SharpDev in XP, The xaml files are slightly different.

After processing, copy it back to the Excel table. It took two or three minutes to solve the problem.

When Windows 10 and vs2015 are coming, as programmers, do not forget that programming aims to solve the problem.

I was also drunk. Ctl + H was enough to solve the problem. I wrote a program! This is because I almost never use Ctl + H to replace all of them: Accidentally changing the data that should not be changed is not a small problem in the unit.

The solution to the problem has never been one, so I should keep it because my starting point is to solve the Excel problem and it is not necessary to operate the Excel.

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.