C# Dosyadan Okuma

RamonMotta

Megapat
Katılım
2 Ağustos 2014
Mesajlar
367
Makaleler
1
Çözümler
2
Daha fazla  
Cinsiyet
Erkek
Arkadaşlar merhaba, dosyadan okuma işlemi için aşağıda yer alan kodları yazdım ve çalışıyor.
C#:
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.Windows.Forms;

namespace bitirme2
{
    public partial class dokuma : Form
    {
        public dokuma()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog file = new OpenFileDialog();
            file.Filter = "Metin Dosyası |*.txt";
            file.ShowDialog();
        }
    }
}
x y z
6147634.02425656 1194979.00210055 1209196.96650085
6147634.02522015 1194979.00228785 1209196.96669166
6147634.02618374 1194979.00247515 1209196.96688247
6147634.02714733 1194979.00266246 1209196.96707328
6147634.02811093 1194979.00284976 1209196.96726408
6147634.02907452 1194979.00303706 1209196.96745489
6147634.03003811 1194979.00322437 1209196.9676457

Yukarıdaki gibi bir .txt dosyasını okuyorum ancak bu dosyayı nasıl işleme koyabileceğim hakkında bir fikrim yok. İşleme koymak istediğim formüllerin kodu da şu şekilde;

C#:
 private void button1_Click(object sender, EventArgs e)
        {
            double wgs84f = 0.00335281, wgs84a = 6378137.00, wgs84b = 6356752.31424518;
            double X, Y, Z;

            X = Convert.ToDouble(textX.Text);
            Y = Convert.ToDouble(textY.Text);
            Z = Convert.ToDouble(textZ.Text);


            double lambda;
            lambda = (Math.Atan(Y / X));
            if (X >= 0)
            {
                lambda = (Math.Atan(Y / X));
            }
            else if (X < 0 && Y >= 0)
            {
                lambda = ((Math.Atan(Y / X)) + 3.1415926535898);

            }
            else if (X < 0 && Y < 0)
            {
                lambda = ((Math.Atan(Y / X)) - 3.1415926535898);
            }
            double lambdaderece;
            lambdaderece = (lambda * (180 / Math.PI));

            double ke2;
            ke2 = ((wgs84a * wgs84a) - (wgs84b * wgs84b)) / (wgs84a * wgs84a);

            double P;
            P = Math.Sqrt((X * X) + (Y * Y));

            double R;
            R = Math.Sqrt((P * P) + (Z * Z));

            double teta;
            teta = Math.Atan((Z * ((1 - wgs84f) * (ke2 * wgs84a / R))) / P);


            double enlem;
            enlem = Math.Atan((Z * (1 - wgs84f) + ke2 * wgs84a * (Math.Pow((Math.Sin(teta)), 3))) / ((1 - wgs84f) * (P - ke2 * wgs84a * (Math.Pow((Math.Cos(teta)), 3)))));

            double fiderece;
            fiderece = (enlem * (180 / Math.PI));

            double yukseklik;
            yukseklik = P * (Math.Cos(fiderece)) + Z * (Math.Sin(fiderece)) - wgs84a * (Math.Sqrt(1 - ke2 * (Math.Pow((Math.Sin(fiderece)), 2))));

            lblBoylam.Text = lambdaderece.ToString();
            lblEnlem.Text = fiderece.ToString();
            lblYukseklik.Text = yukseklik.ToString();
        }

Dosyadan gelen X,Y,Z koordinatlarını nasıl işleme koyabilirim. Önce listbox'a mı yazdıracağım. Burada kafam oldukça karıştı. Şimdiden teşekkürler
 
Stack Overflow üzerinden konu açarsan soruna daha hızlı cevap bulabilirsin hocam. C#'a hakim değilim o yüzden yardımcı olamayacağım.
 
@Evilmonster
C#:
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.Windows.Forms;
using System.IO;

namespace bitirme2
{
    public partial class dokuma : Form
    {
        OpenFileDialog openFile = new OpenFileDialog();
        string line = "";
        public dokuma()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                StreamReader sr = new StreamReader(openFile.FileName);
                while (line != null)
                {
                    line = sr.ReadLine();
                    if (line != null)
                    {
                        foreach (string line in line)
                        {
                            string value = "    "; //koordinatlar arasında ne kadar boşluk varsa o kadar boşluk olmalı.
                            string[] coords = line.Split(value); //3 değerli olacak: x (0), y (1), z (2)
                            listBox1.Items.Add(coords[0]);
                            listBox2.Items.Add(coords[1]);
                            listBox3.Items.Add(coords[2]);
                        }
                    }

                }
            }

        }
    }

Dediğiniz gibi yapmıştım ancak
"Önem Derecesi Kod Açıklama Proje Dosya Çizgi Gizleme Durumu
Hata CS1503 1 bağımsız değişkeni: 'string' öğesinden 'char' öğesine dönüştürülemiyor
Önem Derecesi Kod Açıklama Proje Dosya Çizgi Gizleme Durumu
Hata CS0030 'char' türü 'string' olarak dönüştürülemiyor."
Hatalarını aldım, nasıl düzeltebilirim?
 
Split fonksiyonu karakter bölmesi yapıyorsa bir string dizisi ile bölme yapabilirsiniz.
[CODE lang="csharp" title="C#"]line.Split(new string[] {" "});
//veya
line.Split(new string[] {" "}, StringSplitOptions.None);

//Alternatif olarak
line.Replace(" ", "|").Split('|');[/CODE]
 
nerede kullanacağım bunu
 
Sürekli hata alıyorum, kod çalışmıyor
Ne hatası alıyorsunuz, bu iki seçeneği de denediniz mi?

[CODE lang="csharp" title="C#"]string[] coords = line.Split(new string[] {" "}, StringSplitOptions.None); //1.Seçenek

string[] coords = line.Replace(" ", "|").Split('|'); //2.Seçenek[/CODE]

Dosyada ne kadar boşluk varsa o kadar boşluk koyun.
 
İkisini de denedim boşlukları ayarladım ancak böyle bir hata alıyorum
Oradaki lines'i line yapınca da
Önem Derecesi Kod Açıklama Proje Dosya Çizgi Gizleme Durumu
Hata CS0030 'char' türü 'string' olarak dönüştürülemiyor. bitirme2 hatası alıyorum
 

Dosya Ekleri

  • resim_2021-03-22_170027.png
    53,8 KB · Görüntüleme: 58
Bu siteyi kullanmak için çerezler gereklidir. Siteyi kullanmaya devam etmek için çerezleri kabul etmelisiniz. Daha Fazlasını Öğren.…