W
W
WasTabon2020-11-19 18:08:54
C++ / C#
WasTabon, 2020-11-19 18:08:54

Why is the string not truncated?

private void button1_Click(object sender, EventArgs e)
        {
            txt.ShowDialog();
            textBox1.Text = txt.FileName;
        }

        private void whereSave_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();
            whereSaveTxt.Text = saveFileDialog1.FileName;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string[] str = File.ReadAllLines(textBox1.Text);
            foreach (string s in str)
            {
                s.Substring(0, s.Length -2);
                File.WriteAllText(whereSaveTxt.Text, s);
                Log.Text = "Сохранил " + s;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            slice = Int32.Parse(textBox2.Text);
        }


And how can I make it so that the log is written from a new line and saved in txt from a new line?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Pokrovsky, 2020-11-19
@WasTabon

Why is the string not truncated?

s.Substring(0, s.Length -2);
This method returns a new string rather than modifying the old one
And how can I make it so that the log is written from a new line

Add a line break

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question