user10054311
user10054311

Reputation:

Why does WriteLine in C# change my format in Text File?

So I'm writing an app and without any problem I was getting streamwriter to write new lines using the WriteLine. However, when I got to a certain textbox it automatically started indenting. Please see below image and code:

This is under a save button

        SaveFileDialog sfd = new SaveFileDialog();
        sfd.InitialDirectory = @"C:\DR\Desktop\4-22-18";
        sfd.RestoreDirectory = true;
        sfd.FileName = "G-12";
        sfd.Filter = "txt files(*.txt)|*.txt| Word Files | *.doc";

        if (sfd.ShowDialog()==DialogResult.OK)
        {
            Stream fileStream = sfd.OpenFile();
            StreamWriter sw = new StreamWriter(fileStream);
            sw.WriteLine(lblDate.Text);
            sw.WriteLine(lblTime.Text);
            sw.WriteLine("\r");
            sw.WriteLine("G-12"+"\t"+ lblNotes.Text + " " + txtNotes.Text);
            sw.WriteLine("==========================================");
            sw.WriteLine(lblSG.Text+" "+ nmSG.Text);
            sw.WriteLine("==========================================");
            sw.WriteLine(lblTinWeight.Text + "  " + nmTinWeight.Text);
            sw.WriteLine(lblKIO3.Text + " "+ nmKIO3Volume.Text);
            sw.WriteLine(lblKIO3N.Text + nmKIO3N.Text);
            sw.WriteLine(lblTinPercentage.Text + " "+ lblTinPercent.Text);
            sw.WriteLine(lblTinGram.Text + lblTinGrams.Text);
            sw.WriteLine("==========================================");
            sw.WriteLine(lblNeutWeight.Text+nmNeutWeight.Text);
            sw.WriteLine(lblNeutVolume.Text+nmNaOHVolume.Text);
            sw.WriteLine(lblNeutNormality.Text + nmNaOHNormality.Text);
            sw.Close();
        }

enter image description here

Upvotes: 0

Views: 98

Answers (1)

usr
usr

Reputation: 171178

The text box contains a space. Verify this by looking the value of lblTinWeight.Text (or a different textbox, not sure) in the debugger.

Upvotes: 1

Related Questions