【发布时间】:2011-05-16 13:10:05
【问题描述】:
string[,] desc = new string[255,10];
int descLines = 0;
cont string RDATAPATCH = "rctdata.xdb";
using (StreamReader sr = new StreamReader(RDATAPATCH))
{
descLines = 0;
while (sr.Peek() > -1)
{
sr.ReadLine();
descLines++;
}
desc = new string[descLines, 10];
int line = 0;
sr.BaseStream.Position = 0;
sr.DiscardBufferedData();
while (sr.Peek() > -1)
{
string ltxt = sr.ReadLine();
string[] lstxt = ltxt.Split('|');
for (int x = 0; x < 10; x++)
{
desc[line, x] = lstxt[x];
}
line++;
}
}
string[] sArray = new string[descLines];
for (int x = 0; x < descLines; x++)
{
sArray[x] = desc[x, 7];
}
Array.Sort(sArray);
string[,] tempDesc = new string[descLines, 10];
for (int x = 0; x < sArray.Length; x++)
{
for (int y = 0; y < desc.Length / 10; y++)
{
if (sArray[x] == desc[y, 7])
{
for (int z = 0; z < 10; z++)
{
tempDesc[x, z] = desc[y, z];
}
}
}
}
desc = tempDesc;
我有这段代码,streamreader 加载的文件是这样的:
id|rid|type|date opened|code|<0/1>|<number>|open date|availability('in stoc' or '11.11.2010'>|<0/1/2>
0|0|15fl*20ml/cut|04.2012|200905.101109|1|1|nedeschis|in stoc|2
1|0|15fl*20ml/cut|07.2012|200905.030210|1|1|nedeschis|in stoc|2
2|10|150 teste/cut|11.2012|16813A|1|3|nedeschis|in stoc|2
3|0|15fl*20ml/cut|06.2011|200905.050309|0|11|07.07.2010|in stoc|0
desc 变量按打开日期字符串排序,可以是:'nedeschis'(关闭)或 '11.11.2010'(日期)。 我认为我的算法是错误的,谁能帮助我?
【问题讨论】:
标签: c# string sorting multidimensional-array