c# 怎么把一个txt文件里面的相同行统计出来 变为一行 在后面加上行数。
比如:2113702100500026928388107989211370210050002211370210050002692838810798969283881079...
比如:
211370210050002
6928388107989
211370210050002
211370210050002
6928388107989
6928388107989
211370210050002
6928388107989
6928388107989
211370210050002,4
6928388107989,5 展开
211370210050002
6928388107989
211370210050002
211370210050002
6928388107989
6928388107989
211370210050002
6928388107989
6928388107989
211370210050002,4
6928388107989,5 展开
1个回答
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int xx = 0;
string[] number = System.IO.File.ReadAllLines(@"d:\word\number.txt");
SortedList n1 = new SortedList();
foreach (string num in number)
{
if (!n1.ContainsKey(num))
{
n1.Add(num, 1);
}
else
{
xx=int.Parse( n1[num].ToString());
n1[num] = xx+ 1;
}
}
foreach (string su in n1.Keys)
{
textBox1.AppendText( su + " " + n1[su].ToString()+" \n\r");
}
}
}
}
如有追问,百度消息回答
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int xx = 0;
string[] number = System.IO.File.ReadAllLines(@"d:\word\number.txt");
SortedList n1 = new SortedList();
foreach (string num in number)
{
if (!n1.ContainsKey(num))
{
n1.Add(num, 1);
}
else
{
xx=int.Parse( n1[num].ToString());
n1[num] = xx+ 1;
}
}
foreach (string su in n1.Keys)
{
textBox1.AppendText( su + " " + n1[su].ToString()+" \n\r");
}
}
}
}
如有追问,百度消息回答
更多追问追答
追问
还有就是。我要让它位数保证在20位,不足的补空格。比如:
211370210050002,4
6928388107989,5
211370210050002 ,4
6928388107989 ,5
追答
textBox1.AppendText( su.PadRight(20,' ')+ " " + n1[su].ToString()+" \n\r");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询