GetString and byte data

S

scott_hutter

Given the following:

string x = System.Text.Encoding.Default.GetString(buffer);
x = x.Replace("\r\n", "\r");

If the buffer contains 13 and 10 (2 bytes), can someone please tell me
why the second line cant find and replace? \r\n is supposed to be
equivalent to 13,10 arent they? Im trying to strip out the newline (10)
character.
 
G

Guest

Hi Scott,
I just ran that piece of code and it worked just like I expected it to. I
tried:

byte[] buffer;

buffer = System.Text.Encoding.Default.GetBytes("hello\r\nhow are you?");

string x = System.Text.Encoding.Default.GetString(buffer);
x = x.Replace("\r\n", "\r");

If you look at the contents of buffer you can see byte 13 and 10, after
replacing byte 10 is not longer there in string x.

Mark.
 

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