Private voidImport Phone number Toolstripmenuitem_click (Objectsender, EventArgs e) { using(OpenFileDialog Openfile =NewOpenFileDialog ()) {Openfile.filter="text Files |*.txt"; Openfile.multiselect=false; if(Openfile.showdialog () = =DialogResult.OK) {Thread threadfile=NewThread (() =ReadFile (openfile.filename)); Threadfile. IsBackground=true; Threadfile. Start (); } } } Private voidReadFile (stringfilename) {Txtlog. Invoke (NewAction (() ={Txtlog. AppendText ("start reading mobile phone number". Setlog ()); })); varFile =file.open (filename, filemode.open); intnum =0; intGoods =0; intrepeat =0; using(varstream =NewStreamReader (file)) { while(!Stream. Endofstream) {Lock(lock_send) {if(Sendlist. Count > About) { Break; }} num++; stringLinetemp =Stream. ReadLine (). Trim (); if(Istel (linetemp)) {Lock(lock_send) {vardata = Sendlist. Where (m = M.tel = =linetemp). FirstOrDefault (); if(Data! =NULL) {Repeat++; Continue; }} Goods++; Sendtel _send=NewSendtel (); _send. Tel=linetemp; _send.sms_status=status. Pending delivery; _send.send_time=NULL; ListViewItem Item=NewListViewItem (_send. Tel); Item. SubItems.Add (_send.sms_status. ToString ()); Item. SubItems.Add (_send.send_time); Item. SubItems.Add (""); Listsend.invoke (NewAction (() ={ListViewItem Backitem=LISTSEND.ITEMS.ADD (item); Dic. ADD (_send. Tel, Backitem); })); Lock(lock_send) {sendlist. ADD (_send); }}}} txtlog. Invoke (NewAction (() = { stringLog =string. Format ("Add complete! Valid data is: {0}, filter duplicate data: {1}, total data: {2}", goods. ToString (), repeat. ToString (), Num. ToString ()); Txtlog. AppendText (log. Setlog ()); })); } /// <summary> ///Verify that the phone number is legal/// </summary> /// <param name= "Tel" ></param> /// <returns></returns> Public Static BOOLIstel (stringTel) { Try { if(string. IsNullOrEmpty (tel) | | Tel. Length! = One) { return false; } returnSystem.Text.RegularExpressions.Regex.IsMatch (tel,@"^[1]+[3,4,5,6,7,8]+\d{9}"); } Catch(Exception ex) {return false; } }
A long time ago wrote the code, read the TXT file, a line of a mobile phone number,
It seems to require TXT text file must be UTF8 format, otherwise read out will be garbled.
WinForm Right-click Import phone number