winform提取文本(txt)中想要的内容
2021-07-02 19:04
标签:reg window number user odi rms tar string 文本 using System; namespace WindowsFormsApp1 //List //创建一个Click事件,用于打开读取文件 //if (objOpenFile.ShowDialog() == DialogResult.OK) private void richTextBox1_TextChanged(object sender, EventArgs e) } private void button2_Click(object sender, EventArgs e) if (objOpenFile.ShowDialog() == DialogResult.OK) winform提取文本(txt)中想要的内容 标签:reg window number user odi rms tar string 文本 原文地址:https://www.cnblogs.com/Lee597/p/14962520.html
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//StringBuilder StringBuilder = new StringBuilder();
private void button1_Click(object sender, System.EventArgs e)
{
//System.Windows.Forms.OpenFileDialog objOpenFile = new System.Windows.Forms.OpenFileDialog();
//objOpenFile.Filter = "文本文档|*.txt";
//{
// //this.txtFile.Text = objOpenFile.FileName;
// string[] ReadText = File.ReadAllLines(objOpenFile.FileName, Encoding.Default);
// foreach (string item in ReadText)
// {
// foreach(char number in item)
// {
// //Regex regex = new Regex(@"^\d{24}$");
// if (Convert.ToInt32(number) >= 48 && Convert.ToInt32(number) // //if (item.ToUpper().Contains(""))//搜索指定字符串
// {
// //ZZZString.Add(number);//搜索到的内容存入ZzzString集合
// //ZZZString.Append(number.ToString());
// StringBuilder.Append(number);
// //richTextBox1.Text += item.ToString() + "\r\n";//添加一个richTextBox
// //label1.Text = ZzzString.Count + "条";//添加一个label
// }
// }
// if (!"".Equals(StringBuilder.ToString())) {
// richTextBox1.Text += "6J" + StringBuilder + "\n";
// StringBuilder.Clear();
// }
// }
//}
}
{
{
System.Windows.Forms.OpenFileDialog objOpenFile = new System.Windows.Forms.OpenFileDialog();
objOpenFile.Filter = "文本文档|*.txt";
{
//this.txtFile.Text = objOpenFile.FileName;
string[] ReadText = File.ReadAllLines(objOpenFile.FileName, Encoding.Default);
int a = 0;string b = "";
foreach (string item in ReadText)
{
if (a == 1) {
string input_links = Regex.Replace(item," ", "");
richTextBox1.Text += "6J" + input_links + ":" + b + "\r\n";
a = 0;
}
if (item.ToUpper().Contains("6J")) {
a = 1;
}
if (item.ToUpper().Contains("(Z) A")) {
b = "ZA";
}
if (item.ToUpper().Contains("(Z) B")) {
b = "ZB";
}
if (item.ToUpper().Contains("(Z) C")) {
b = "ZC";
}
if (item.ToUpper().Contains("(Z) D")) {
b = "ZD";
}
}
System.IO.File.WriteAllText(@"C:\Users\LG\Desktop\提取的6J码.txt", richTextBox1.Text);
}
}
}
}