VC#
I have a text file contains a pair of numbers spilted by comma and grouped by special markers
Like 1000, 2000 and 3000 serial no.
How can I sort these number according to the first column.
Here the Orginal text file named data.txt:
1000
10, 614
33, 544
- 30, 245
- 25, 311
- 10, 407
0 ,115
20, 436
2000
25, 236
0, 987
- 20, 409
- 60, 201
- 55, 211
- 10 ,415
45, 844
55,678
3000
- 10, 567
0 , 777
10, 955
24, 569
- 35, 300
35, 765
- 45, 335
The sorted file should look like this:
1000
- 30, 245
- 25, 311
- 10, 407
0 ,115
10, 614
20, 436
33, 544
2000
- 60, 201
- 55, 211
- 20, 409
- 10 ,415
0, 987
25, 236
45, 844
55,678
3000
- 45, 335
- 35, 300
- 10, 567
0 , 777
10, 955
24, 569
35, 765
What I have tried:
StreamReader sr= new StreamReader(data.txt);
StreamWriter sw= new StreamWriter(soted.txt,true);
for(str=1000; str <= 3000; str += 1000)
{
while((line = sr.ReadLine()) != null)
{
if line.Contains(str)
{
char[] sep = new char[]{','};
string[] sArr = line.Split(sep);
for(i=0; i < sArr.Length-1;i++)
{
xArr[i] = Int32.Parse(sArr[0]);
yArr[i] = Int32.Parse(sArr[1]);
sw.WriteLine(" {0} {1},Convert.ToInt32(xArr[i].ToString(),Convert.ToInt32(yArr[i].ToString());
}
}
}
}