110,539
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo dir = new DirectoryInfo(".");//new DirectoryInfo(".")
FileInfo[] inf = dir.GetFiles();
StreamReader rd;//用于打开“A5E”文件
Storage stor = new Storage();//实例化
foreach (FileInfo finf in inf)
{
if (finf.Extension.Equals(".A5E")) //如果扩展名为“.A5E”
{
string path = finf.Name;
rd = File.OpenText(path);
string s = rd.ReadToEnd();
string[] sArray = s.Split('&'); // split the string into seperate strings using &
Storage.counter = 0;
for (int i = 0; i < sArray.Length; i++)//i是区分按照& split分开的部分
{
if (i % 2 == 1)
{
string[] lineArray = sArray[i].Split('\n'); //利用正则表达式将字符串中的数字提取出来分别保存在小数数组中
for (int ii = 7; ii < (lineArray.Length - 3); ii++) //ii是为了区分everyline of reinforcement layers
{
Storage.counter++;
MatchCollection vMatchs = Regex.Matches(lineArray[ii], @"((-?\d+)(\.\d+)?)");//读取出lineArray中的小数,并存在数组中
double[] vDouble = new double[vMatchs.Count];
for (int j = 0; j < vMatchs.Count; j++)//j是为了迭代读取出存储在vMatch中的每一行的小数
{
vDouble[j] = double.Parse(vMatchs[j].Value);//store the number of the line into vInts array
}
stor.NS = vDouble[0];
stor.averageStress = vDouble[4];
Storage.Dic.Add(Storage.counter, stor);/////出现了大大的问题,字典中的旧值被新值覆盖了
}
}
}
}
}
}
}
public class Storage
{
public static int counter = 0;//用于对A5E中的字典进行计数(key)
public double NS
{ get; set; }
public double averageStress
{ get; set; }
public static SortedDictionary<int, Storage> Dic = new SortedDictionary<int, Storage>();
}
}