当前位置:编程学习 > C#/ASP.NET >>

如何将文本文件转换成数据矩阵,求源代码

下面是部分的文本文件
10
52.755798,23.644300,2.989400,0.243900,0.126500,-86.642899,34.628399,11.840000,6.159000,256.009003
58.036301,16.085800,2.903100,0.231300,0.120600,4.614800,18.862000,-12.330900,4.913200,133.565002
51.573101,25.263800,3.325600,0.177700,0.091400,8.340000,40.431400,-17.456100,3.174000,235.106995
27.876200,17.401300,2.770100,0.373500,0.233400,-0.233700,-18.508900,-11.971600,11.587400,195.272003
21.068899,13.621500,2.604200,0.514900,0.272400,22.651300,12.691100,8.893200,5.384400,180.054993
49.737000,21.533800,2.887600,0.255200,0.158700,-5.976300,-34.083599,12.426600,19.187000,208.483994
21.535900,12.537200,2.386500,0.464100,0.236100,13.475700,13.607100,-9.993200,15.312000,166.529007
32.294701,13.000800,2.477100,0.560000,0.385000,10.800200,26.720699,-12.750400,39.825298,75.983803
40.824600,18.185600,2.596000,0.367600,0.249700,48.250702,-6.960600,10.130200,9.868000,128.033997
26.296801,12.111100,2.505100,0.434400,0.248400,3.991700,22.492599,-9.925600,0.085000,170.774994
23.491400,10.225000,2.318100,0.543300,0.300500,32.244900,-16.329000,-9.417900,60.549099,26.088900
97.719002,31.345100,3.095900,0.283900,0.196900,-80.291397,-80.363098,-20.897400,9.589700,279.075012
53.745998,26.097500,2.887300,0.273500,0.145800,46.481701,67.439400,12.201000,36.877300,49.882000
33.838501,23.101801,3.071000,0.228400,0.118500,-26.862700,-18.527800,-14.106600,9.088300,230.897003
68.242203,26.356501,3.796800,0.166700,0.096700,16.260201,60.392700,-17.422001,2.555000,256.515015
21.162800,12.203900,2.347300,0.471900,0.253900,-0.406000,8.838700,10.792500,35.800999,160.436005
37.148998,15.631300,2.455600,0.542900,0.313500,-20.830601,-28.852600,-12.665600,13.729000,159.410995
16.360701,11.570900,2.352200,0.595600,0.308900,-2.393500,6.741900,-4.005400,35.426998,155.949997
32.275799,16.403400,2.656600,0.443200,0.272300,8.326500,29.338100,-17.998100,12.319500,206.938995
102.285004,28.541599,3.192100,0.286500,0.149400,-26.033100,-85.609100,-12.823700,2.661000,373.445007
85.804901,32.227798,3.779800,0.160900,0.086800,22.766899,77.315498,-11.730400,1.353600,288.764008
32.853001,19.941200,2.986500,0.324900,0.164500,-8.462400,18.199900,10.027300,8.724000,174.955002
40.346298,19.842199,2.947400,0.217800,0.110000,48.662300,19.603800,-16.762800,14.512200,102.806999
29.021299,11.558000,2.404800,0.409400,0.214600,7.743400,16.316999,-6.563300,9.257200,138.537994
77.354301,41.925800,4.044300,0.106600,0.054000,67.430099,71.413300,18.985300,3.703900,198.406006
53.964802,17.914801,3.201500,0.272900,0.141200,33.009602,60.641998,-6.508000,0.857000,271.062988
53.563202,41.990200,2.844200,0.279200,0.153900,-55.782501,-45.045300,-15.821000,61.555199,124.957001
57.109501,19.013901,2.652700,0.246900,0.130100,-25.046400,44.862099,-11.324700,34.612999,168.147003
40.966202,17.728399,2.924800,0.254500,0.130200,17.129900,-15.280600,-11.595100,4.324000,137.016006
132.953995,24.184500,3.152400,0.233700,0.138300,-99.193001,-69.383202,21.453800,0.360000,322.165985
33.114101,24.227600,2.953000,0.329800,0.192200,8.512100,22.766800,17.846500,47.730202,81.403702
51.264000,22.130600,3.254300,0.228300,0.115000,0.050100,44.554401,12.167800,10.649000,198.326996
21.681601,13.228900,2.489300,0.583500,0.354900,18.412800,19.460100,8.596100,55.726200,103.012001
81.125397,32.318600,3.351100,0.172900,0.088000,67.017899,77.508301,29.555500,10.340000,188.938995
89.198898,13.316800,2.702400,0.339300,0.203400,-99.292900,59.374500,11.451000,4.263700,231.149994
47.215599,18.711500,3.070000,0.211900,0.121300,-1.096200,-22.759501,10.422600,3.400000,195.921997
13.070200,11.103300,2.168800,0.759300,0.389800,-14.934200,3.438600,11.816600,80.353302,218.839996
28.467800,20.049601,2.743500,0.346600,0.235600,17.997499,19.040300,-14.625600,10.618000,124.779999
24.566099,17.715000,2.675800,0.343900,0.190900,5.998500,18.439600,8.650100,11.018000,193.054001
38.875401,18.523199,3.116100,0.249500,0.133600,-15.026400,9.815400,-5.863100,3.361000,166.899002
54.437500,32.782299,3.117400,0.155700,0.079700,56.832600,12.294700,16.130800,2.639900,144.710007
34.687199,15.580200,2.548400,0.396000,0.224900,1.219700,23.202900,-8.691400,4.286000,209.891006
59.658699,22.476000,3.046100,0.205000,0.103900,8.212800,48.775200,-12.461800,12.842000,169.649994
22.049801,16.528999,2.686600,0.448600,0.250000,-6.284700,-12.769300,-4.799300,9.097000,190.807007
求高手指点?我是菜鸟 --------------------编程问答-------------------- 高手出来给解决了不就得了

一个 X 10 矩阵

尼玛 要是学算法,这是第一节课就该会的东西
--------------------编程问答--------------------
		string[] lines = File.ReadAllLines(Server.MapPath("~/test.txt"));
double[,] r = new double[lines.Length, lines[0].Split(',').Length];
for (int i = 0; i < r.GetLength(0); i++)
{
string[] line = lines[i].Split(',');
for (int j = 0; j < r.GetLength(1); j++)
r[i, j] = double.Parse(line[j]);
}

输出:
		for (int i = 0; i < r.GetLength(0); i++)
{
for (int j = 0; j < r.GetLength(1); j++)
Response.Write(r[i, j] + "    ");
Response.Write("<br/>");
}
--------------------编程问答-------------------- 谢谢咯~~~
--------------------编程问答-------------------- 我还有个问题要请教高手,如何在windows窗体中实现呢~~这个应该是在控制台应用程序中实现的吧~~
--------------------编程问答-------------------- 还有还有~~提示说当前上下文中不存在名称“Server”“Response”是啥意思啊
--------------------编程问答-------------------- 将Server.MapPath("~/test.txt")替换成你的文件路径和文件名。
将Response.Write替换成MessageBox.Show --------------------编程问答-------------------- 谢谢,现在显示,找不到名称File又是怎么一回事呢~~还有就是Response.Write(r[i, j] + "    ");中的    是神马呢?请高手给予解答啊~~ --------------------编程问答-------------------- 找不到文件是你路径指定错误。应该用双反斜杠来表示。
后者,你替换成空格好了。 --------------------编程问答--------------------  是File.ReadAllLines中的这个找不到名称File该怎么解决呢? --------------------编程问答-------------------- 你把文件放到C:\,叫做C:\1.txt

string[] lines = File.ReadAllLines("c:\\1.txt");
--------------------编程问答-------------------- 谢谢哈~~ --------------------编程问答-------------------- 有一个问题就是:为神马最后显示出来的并非以矩阵形式显示出来而是一个数字一个数字的蹦出来呢?不是整个矩阵都显示出来呢? --------------------编程问答-------------------- 求代码啊求代码~~
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,