我想读取带有“#”附加到单词的文件我想从单词
输入文件中删除它
a, 00001740, 0.125, 0, able#1
a, 00001740, 0.125, 0, play#2
a, 00002098, 0, 0.75, unable#1
我想要以下没有#
输出的格式应该是这个
a, 00001740, 0.125, 0, able
a, 00001740, 0 .125, 0, play
a, 00002098, 0, 0.75, unable
我写下面的代码
TextWriter tw = new StreamWriter("D:\\output.txt");
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
StreamReader reader = new StreamReader("D:\\input.txt");
string line;
while ((line = reader.ReadLine()) != null)
{
Regex expression = new Regex(@"\b\w+(?=#\d*\b)");
var results = expression.Matches(reader.ToString())
foreach (Match match in results)
{
tw.Write(match);
}
tw.Write("\r\n");
}
tw.Close();
reader.Close();
}
textBox1.Text = "";
}
}