0

I've a table like the one below. I check my data in "column 1(TC)" with the algorithm. I want to show the "true or false" values in "column 7(Kontrol)". How can I do that? I can read with Streamreader but cannot write to the correct column with Streamwriter.

Image

 private void button1_Click(object sender, EventArgs e)
    {

        string fileName = @"D:\verim.txt";
        string fileNamee = @"D:\verim2.txt";
        StreamReader SR = new StreamReader(fileName);
        StreamWriter outputFile = System.IO.File.AppendText(fileNamee);

        string metin = SR.ReadLine();
        metin = SR.ReadLine();
       
        while (metin != null)
        {

            string[] sutunlar = metin.Split('\t');              
                if (metin.Contains("TC") == false)
                {
                    string sonuc = (sutunlar[0]);
                    bool returnvalue = false;
                    if (sonuc.Length == 11)
                    {
                        Int64 ATCNO, BTCNO, TcNo;
                        long C1, C2, C3, C4, C5, C6, C7, C8, C9, Q1, Q2;

                        TcNo = Int64.Parse(sonuc.ToString());

                        ATCNO = TcNo / 100;
                        BTCNO = TcNo / 100;

                        C1 = ATCNO % 10; ATCNO = ATCNO / 10;
                        C2 = ATCNO % 10; ATCNO = ATCNO / 10;
                        C3 = ATCNO % 10; ATCNO = ATCNO / 10;
                        C4 = ATCNO % 10; ATCNO = ATCNO / 10;
                        C5 = ATCNO % 10; ATCNO = ATCNO / 10;
                        C6 = ATCNO % 10; ATCNO = ATCNO / 10;
                        C7 = ATCNO % 10; ATCNO = ATCNO / 10;
                        C8 = ATCNO % 10; ATCNO = ATCNO / 10;
                        C9 = ATCNO % 10; ATCNO = ATCNO / 10;
                        Q1 = ((10 - ((((C1 + C3 + C5 + C7 + C9) * 3) + (C2 + C4 + C6 + C8)) % 10)) % 10);
                        Q2 = ((10 - (((((C2 + C4 + C6 + C8) + Q1) * 3) + (C1 + C3 + C5 + C7 + C9)) % 10)) % 10);
                        returnvalue = ((BTCNO * 100) + (Q1 * 10) + Q2 == TcNo);
                    }
                    if (returnvalue && metin.Contains("Kontrol") == false)
                        
                        {                   
                        string kelime = "True";
                            outputFile.WriteLine(kontrollist +kelime);                              
                        }
                        else
                    {
                        string kelime2 = "False";
                    outputFile.WriteLine(kelime2);
                }                      
                
                }
                metin = SR.ReadLine();     
            }
        outputFile.Close();
    }
Nuri
  • 11
  • _"cannot write to the correct column with Streamwriter"_ -- meaning what, exactly? The general technique is straightforward: you need to read the data into some data structure, either one line at a time, or the entire file into some collection object, then write the data back out to a new file, again either one line at a time (i.e. immediately after reading one line and modifying it according to your needs) or writing the whole collection object which has already had its data updated according to your needs. See duplicate for the answer to that general technique. If you have some ... – Peter Duniho May 19 '21 at 07:06
  • ... _specific_ difficulty involved in accomplishing this, either fix this question or post a new one in which you have provided a proper [mcve], along with a clear and detailed explanation of what that code does, how that's different from what you want, and what _specifically_ you need help with. – Peter Duniho May 19 '21 at 07:06

0 Answers0