txt1.AppendText appends extra char

R

Ron

Greetings,

I am writing text to a multi line textbox on a timer as
follows:

txt1.AppendText(@"/* " + DateTime.Now.ToString() + "\n");

Here is what gets displayed

/* 1/1/2004 11:12:11 AM|

There is a pipe | char at the end of the string. I am
guessing it is the "\n" carriage return char. How can I
write text to the multi line textbox with a newline and
without this pipe char?

Thanks,
Ron
 
N

Nicholas Paldino [.NET/C# MVP]

Ron,

Instead of appending \n, try using Environment.NewLine.

Also, make sure that the Multiline property is set to true on the
textbox.

Hope this helps.
 
R

Ron

Thanks. That did the trick. May I ask this:

Is there a situation where "\n" is preferred over
Environment.NewLine?

If I write data to a delimited text file, does it make any
difference if I end a row of data with "\n" or
Environment.Newline?

The only downside I can see with Environment.Newline is
that it is more chars than "\n".

-----Original Message-----
Ron,

Instead of appending \n, try using Environment.NewLine.

Also, make sure that the Multiline property is set to true on the
textbox.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Greetings,

I am writing text to a multi line textbox on a timer as
follows:

txt1.AppendText(@"/* " + DateTime.Now.ToString() + "\n");

Here is what gets displayed

/* 1/1/2004 11:12:11 AM|

There is a pipe | char at the end of the string. I am
guessing it is the "\n" carriage return char. How can I
write text to the multi line textbox with a newline and
without this pipe char?

Thanks,
Ron


.
 
N

Nicholas Paldino [.NET/C# MVP]

Ron,

Well, I can't think of one. I mean, you might have to write files that
require just the new line character. However, it's pretty common to see the
\r\n combination nowadays.

For your delimited text file, it depends on what is going to process it.
I would think that most modern programming libraries would be able to handle
the \r\n, but you will have to test it to find out.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ron said:
Thanks. That did the trick. May I ask this:

Is there a situation where "\n" is preferred over
Environment.NewLine?

If I write data to a delimited text file, does it make any
difference if I end a row of data with "\n" or
Environment.Newline?

The only downside I can see with Environment.Newline is
that it is more chars than "\n".

-----Original Message-----
Ron,

Instead of appending \n, try using Environment.NewLine.

Also, make sure that the Multiline property is set to true on the
textbox.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Greetings,

I am writing text to a multi line textbox on a timer as
follows:

txt1.AppendText(@"/* " + DateTime.Now.ToString() + "\n");

Here is what gets displayed

/* 1/1/2004 11:12:11 AM|

There is a pipe | char at the end of the string. I am
guessing it is the "\n" carriage return char. How can I
write text to the multi line textbox with a newline and
without this pipe char?

Thanks,
Ron


.
 
J

Jon Skeet [C# MVP]

Nicholas Paldino said:
Well, I can't think of one. I mean, you might have to write files
that require just the new line character. However, it's pretty common
to see the \r\n combination nowadays.

It really depends on the target platform of the file. \n is pretty
standard on Unix, \r\n is pretty standard on Windows.

IIRC, most internet protocols require \r\n.
 
R

Ron

Yes, I am exclusively on Windows systems, so \r\n looks
like it is it..

Thanks all for your help.

It really depends on the target platform of the file. \n
is pretty
standard on Unix, \r\n is pretty standard on Windows.

IIRC, most internet protocols require \r\n.
<<

-----Original Message-----
Ron,

Well, I can't think of one. I mean, you might have to write files that
require just the new line character. However, it's pretty common to see the
\r\n combination nowadays.

For your delimited text file, it depends on what is going to process it.
I would think that most modern programming libraries would be able to handle
the \r\n, but you will have to test it to find out.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thanks. That did the trick. May I ask this:

Is there a situation where "\n" is preferred over
Environment.NewLine?

If I write data to a delimited text file, does it make any
difference if I end a row of data with "\n" or
Environment.Newline?

The only downside I can see with Environment.Newline is
that it is more chars than "\n".

-----Original Message-----
Ron,

Instead of appending \n, try using Environment.NewLine.

Also, make sure that the Multiline property is set
to
true on the
textbox.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Greetings,

I am writing text to a multi line textbox on a timer as
follows:

txt1.AppendText(@"/* " + DateTime.Now.ToString() + "\n");

Here is what gets displayed

/* 1/1/2004 11:12:11 AM|

There is a pipe | char at the end of the string. I am
guessing it is the "\n" carriage return char. How can I
write text to the multi line textbox with a newline and
without this pipe char?

Thanks,
Ron


.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top