denise28

做不成学术帝,就一辈子做吃货~
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#读取数据流处理

Posted on 2010-07-16 14:46  denise28  阅读(2693)  评论(0)    收藏  举报

从xml文件流中读取大量的数据

<SeriesOfScalar hopSize="PT10N1000F" totalNumOfSamples="594">
<Raw>240.98361 240.98361 233.33333 233.33333 72.89256 72.89256 245.0 245.0 249.15254 249.15254 61.25 61.25 235.82887 235.82887 66.818184 66.818184 239.67392 239.67392 238.37837 238.37837 237.09677 237.09677..................</Raw>
</SeriesOfScalar>

数据之前用空格隔开;

还有一类是得到的矩阵类数组

<Raw mpeg7:dim="1 10 5">0.20493282 -0.119554184 0.27260712 -0.09809845 0.030316312&#13;
0.31394926 -0.42930833 -0.6578707 -0.5285229 0.06091692&#13;
0.29194596 -0.4717088 -0.07935622 0.6014706 -0.52537566&#13;
0.27276152 -0.22869915 0.20385297 0.19142622 0.6619794&#13;
0.25855646 -0.27435502 0.2164415 0.0830914 0.101162106&#13;
0.25216228 -0.118959695 0.29983753 -0.11449488 0.22105172&#13;
0.2905421 0.048200376 0.46687692 -0.49792215 -0.46110636&#13;
0.34469113 0.20671746 0.07034116 -0.038591165 -0.082390495&#13;
0.39359176 0.47082967 -0.23057169 0.16216423 0.013164998&#13;
0.45959634 0.41283235 -0.17945303 0.13001108 0.049549058&#13;
</Raw>

其中&#13;读入以后实际上是"\r\n",就是换行回车

处理这些数据的方法是先读入

然后运用 split(' ')  对数据进行分割,然后转化类型存入数组进行排序处理

                                string s = reader.ReadString();
                                string[] arryOfString = s.Split( ' ' );
                                double[] arryOfDouble = new double[arryOfString.Length]

矩阵那堆数据

                                string s = reader.ReadString();
                                string[] arryOfString = s.Replace( "\r\n" , " " ).Split(' ');
                                double[] arryOfDouble = new double[arryOfString.Length];

然后是快速排序

private static void QuickSort(ref double[] sort, int start, int end)
        {
            int i = start;
            int j = end + 1;
            double val = sort[i];
            do
            {
                do
                {i++;} while (sort[i] > val && i < end);
                do
                {j--;} while (sort[j] < val && j > start);
                if (i < j)
                {
                    double temp;
                    temp = sort[i]; sort[i] = sort[j]; sort[j] = temp;
                }
            } while (i < j);

            sort[start] = sort[j]; sort[j] = val;
            if (j > start + 1) QuickSort(ref sort, start, j - 1);
            if (j < end - 1) QuickSort(ref sort, j + 1, end);
        }