本文介绍了C#RichTextBox问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,
那里有一个txt文件,其数据格式如下:
86
12 23
45 56
.....
.....

.....
87 56
102
12 23
45 56
.....
.....

.....
87 56

12,23代表一个点的x,y,我需要获取前86个点的平均x,y,然后是下一个102点,然后是下一个x点,在c#中,请帮助我

Dear frieds,
there I have a txt file, in which data formats are as follows:
86
12 23
45 56
.....
.....

.....
87 56
102
12 23
45 56
.....
.....

.....
87 56

12,23 stands for the x,y of a point, I need to get the average x,y of first 86 points, then next 102 points then next x points etc, in c#, please help me

推荐答案



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int linecout=0;
        private void button1_Click(object sender, EventArgs e)
        {
            string line;
            
            StreamReader sr = new StreamReader(@"d:\1.nnt");
            string[] str = sr.ReadToEnd().Split('\n');
            List<point> list = new List<point>();
            for (int iLoop = 0; iLoop < str.Length; iLoop++)
            {
               
              
                int yighindaa = 0;
                int yighindab = 0;
                int a, b;
                int sanx = 0;
                int sany = 0;
                int currenline = 0;
                line = str[iLoop].ToString();
                var regex = new Regex(@"\s");
                bool space;
                space = line.ToString().Contains(" ");
                if (space == false)
                {

                    currenline = iLoop;
                    linecout = int.Parse(str[iLoop].ToString());
                    //MessageBox.Show(currenline.ToString()+","+linecout.ToString());
                   
                }
                else if (space == true)
                {
                   
                    for (int k = currenline+1; k < linecout+1; k++)
                    {
                        //list.Add(new Point(Int32.Parse(line.Split(' ')[0]), Int32.Parse(line.Split(' ')[1])));
                        //a = int.Parse(list[k].X.ToString());
                        
                        //b = int.Parse(list[k].Y.ToString());
                        //yighindaa = yighindaa + a;
                        //sanx = yighindaa / list.Count;
                        //yighindab = yighindab + b;
                        //sany = yighindab / list.Count;
                        MessageBox.Show();
                    }
                    //richTextBox1.Text = "X(average)=" + sanx.ToString() + "," + "Y(average)=" + sany.ToString();
                }
               
                
            }
        }
    }
}
</point></point>



我写了这些代码,但不能解决问题,此代码有一些问题,请帮助我修改...谢谢



I wrote these codes ,but it could not solve the problem ,there have some problems on this code ,please help me to revise...thanks


这篇关于C#RichTextBox问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 22:59