Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected character is displayed in the textbox

Tags:

c#

.net

winforms

I have a very simple .NET program. It's just to write a string to the textbox. There is a strange character appearing at the end of my string.

enter image description here

This happens only on my 32-bit XP box. The same program works fine on another 64bit Windows 2008 machine.

The program is as simple as this.

    private void Form1_Load(object sender, EventArgs e)
    {
        textBox1.Text = "Hello\n\0\0\0\0\0\0";
    }

I know it's odd to add \0 at the end of the string and I can trim them before applying to the textbox. The textbox is set to allow multi-line.

Just out of curiousity, does anybody know where the problem comes from? Both machines got .NET 3.5 SP1 installed. Both of them are set to have the same regional settings. I doubt if it is related to 32-bit or 64-bit.

UPDATE

Thanks to @DBM and @Andrew. The strange character is coming from \n but nothing to do with \0. Now, it sounds like Windows 2008 can understand both \r\n and \n. Can anybody confirm that?

like image 821
Harvey Kwok Avatar asked Dec 22 '22 13:12

Harvey Kwok


1 Answers

Standard end-of-line sequence in Windows is \r\n. The text box isn't recognising the \n as a new-line without the preceding carriage return (\r).

like image 158
Andrew Cooper Avatar answered Jan 05 '23 14:01

Andrew Cooper