String includes RETURN KEY

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi, all.

Here is a stupid question.

I have three string
string str1 =" test1 ";
string str2 =" test21\ntest22\ntest23"; (\n means return key)
string str3 =" test3 ";
I write them to a file(test.txt) by using Stream.write();
I open the file:
it is:
test1
test21
test22
test23
test3
when I read test.txtby using Stream.read(), I can not restore it again.I got
5 string.
indeed, It should three string?

What should I do?

Thanks
 
Can you provide more code. Streams work on bytes and there is no concept of
"5 string" since you are simply requesting the number of bytes. Are you
actually using a StreamReader or something?
 
jeff said:
hi, all.

Here is a stupid question.

I have three string
string str1 =" test1 ";
string str2 =" test21\ntest22\ntest23"; (\n means return key)
string str3 =" test3 ";
I write them to a file(test.txt) by using Stream.write();
I open the file:
it is:
test1
test21
test22
test23
test3
when I read test.txtby using Stream.read(), I can not restore it again.I got
5 string.
indeed, It should three string?

What should I do?

Thanks
 
try using the "@" literal string character in front of str2.
I did not try it but its an idea.
 
\n *is* the end of a line and is working correctly.

How can you want some of your ends of lines not to be ends of lines?

But if what you mean is that you want to preserve the strings, I suppose you
could convert every end of line mark to something else before writing the
string out, and undo the conversion after reading it in again.
 
if you want new line Use :
"\r\n" - new line in windows
( '\n' = new line in Linux , '\r' = new line in Mac)
If you what '\n' in the file Use "\\n"
 
Back
Top