private void textBox1_DragDrop(object sender, DragEventArgs e)
{
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
textBox1.Text = path;
}
private void button1_Click(object sender, EventArgs e)
{
string path = @textBox1.Text;
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
StreamReader read = new StreamReader(fs, Encoding.Default);
FileStream fs1 = new FileStream(@"C:\Users\Administrator\Desktop\test1.txt", FileMode.CreateNew, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs1);
string str;
int seed = 1;
while ((str = read.ReadLine()) != null)
{
if (str.Contains("Capacitance :"))
{
int ii = str.IndexOf("Capacitance :");
string leftstring = str.Substring(0, ii + 13);
string rightstring = str.Substring(ii + 13 + 4, str.Length - ii - 13 - 4);
//Thread.Sleep(10);
seed++;
int rrrandom = (int)(new Random(seed).Next(10, 95));
string newstring = leftstring + " " + rrrandom + rightstring;
sw.WriteLine(newstring);
}
else
{
sw.WriteLine(str);
}
}
sw.Flush();
fs.Close();
read.Close();
}
多个文本是指选择多个文本文件嘛 ?? 设置OpenFileDialog的 Multiselect = true; 可以多选; 通过
.FileNames
可以获取文件名数组;循环遍历就成了