private void button1_Click(object sender,
EventArgs e)
{
quchongfu(textBox1);
}
//去除重复项
int chongfu;
private void quchongfu(TextBox
tb)//textBox控件名称
{
chongfu =
0;
for (int i
= 0; i < tb.Lines.Length; i++)
{
for (int j = i + 1; j
< tb.Lines.Length; j++)
{
Delay(100);//延时执行
if (tb.Lines[i].Equals(tb.Lines[j]))
{
tb.Lines[j].Remove(0);
chongfu++;
}
}
}
MessageBox.Show("一共有" + tb.Lines.Length +
"个原始数据\r\n去除了" + chongfu + "个重复数据\r\n" +
"得到" + (tb.Lines.Length - chongfu) + "个不重复数据");
//延时执行
private void Delay(int mm)
{
DateTime
current = DateTime.Now;
while
(current.AddMilliseconds(mm) > DateTime.Now)
{
Application.DoEvents();
}
return;
}
修正版
private void button1_Click(object sender,
EventArgs e)
{
string
content=quchongfu(textBox1);
int
hangshu = textBox1.Lines.Length;
textBox2.Text = content;
MessageBox.Show("一共有" + (hangshu - kongbaihang) +
"个原始数据\r\n去除了" + chongfu +
"个重复数据\r\n消除了"+kongbaihang+"个空白行\r\n得到"
+ (hangshu - kongbaihang - chongfu) + "个不重复数据");
}
//去除重复项
int chongfu;
int kongbaihang;
private string quchongfu(TextBox
tb)//textBox控件名称
{
chongfu =
0;
kongbaihang = 0;
string
content = "";
for (int i
= tb.Lines.Length - 1; i >= 0; i--)
{
bool jia =
true;//判断是否要加上
//判断空白行
if (tb.Lines[i] == "")
{
kongbaihang++;
jia = false;
}
if (tb.Lines[i] != "")
{
for (int j = i - 1; j >= 0;
j--)
{
Delay(1);//延时执行,单位毫秒
if
(tb.Lines[i].Equals(tb.Lines[j]))
{
chongfu++;
jia = false;
}
}
if (jia == true)
{
content =
tb.Lines[i] + "\r\n" + content;
}
}
}
return
content;
}
#region 延时,方法
//延时执行
private void Delay(int mm)
{
DateTime
current = DateTime.Now;
while
(current.AddMilliseconds(mm) > DateTime.Now)
{
Application.DoEvents();
}
return;
}
#endregion
最终版
private void button1_Click(object sender,
EventArgs e)
{
string
content=quchongfu(textBox1);
int
hangshu1 = textBox1.Lines.Length;
int
hangshu2 = textBox2.Lines.Length;
textBox2.Text = content;
MessageBox.Show("一共有" + (hangshu1 - kongbaihang) +
"个原始数据\r\n去除了" + chongfu +
"个重复数据\r\n消除了"+kongbaihang+"个空白行\r\n得到"
+ (hangshu1 - kongbaihang - chongfu) + "个不重复数据");
}
//去除重复项
int chongfu;
int kongbaihang;
private string quchongfu(TextBox
tb)//textBox控件名称
{
chongfu =
0;
kongbaihang = 0;
string
content = "";
for (int i
= 0; i <tb.Lines.Length; i++)
{
bool jia =
true;//判断是否要加上
//判断空白行
if (tb.Lines[i] == "")
{
kongbaihang++;
jia = false;
}
if (tb.Lines[i] != "")
{
for (int j = 0; j < i;j++ )
{
Delay(1);//延时执行,单位毫秒
if
(tb.Lines[i].Equals(tb.Lines[j]))
{
chongfu++;
jia = false;
}
}
if (jia == true)
{
content =
content + tb.Lines[i] + "\r\n";
}
}
}
return
content;
}
#region 延时,方法
//延时执行
private void Delay(int mm)
{
DateTime
current = DateTime.Now;
while
(current.AddMilliseconds(mm) > DateTime.Now)
{
Application.DoEvents();
}
return;
}
#endregion