C#RichTextBox问题 [英] C# richtextbox problem

查看:91
本文介绍了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

推荐答案

所以-这有点作业的味道,所以我不会为您编写代码:

1)读取一行-将其转换为整数.
2)开始累计.
3)循环遍历(1)中的读取次数
3.1)读取一条线,转换为点值.
3.2)在累计总数中包括点.
4)生成平均点并输出.
5)如果文件中还有更多行,请重复(1)

只要您知道平均点的计算是多少,就可以使用C#编写代码,这很容易-我不知道.它可以是到固定点的距离,也可以是Xs的平均值和Ys的平均值.
So - this smells of homework, so I''ll not code it for you:

1) Read a line - convert it to an integer.
2) Start a cumulative total.
3) Loop though the number of times read in (1)
3.1) Read a line, convert to a point value.
3.2) Include point in cumulative total.
4) Generate the average point, and output it.
5) If there are more lines in your file, repeat from (1)

It''s pretty easy to code in C#, provided you know what the average point calculation is - I don''t. It could be a distance from a fixed point, or just an average of the Xs and an average of the Ys.


有人可以帮我吗?这实际上不是作业
could anyone help me? this is not a homework actually


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问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆