473,411 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

String includes RETURN KEY

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



Jul 21 '05 #1
5 1144
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" <je**@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
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


Jul 21 '05 #2


"jeff" wrote:
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


Jul 21 '05 #3

try using the "@" literal string character in front of str2.
I did not try it but its an idea.

"jeff" wrote:
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


Jul 21 '05 #4
\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.
"jeff" <je**@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
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


Jul 21 '05 #5
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"

"jeff" <je**@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
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


Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: usgog | last post by:
I need to implement a function to return True/false whether String A contains String B. For example, String A = "This is a test"; String B = "is is". So it will return TRUE if String A includes two...
28
by: David Rubin | last post by:
I looked on google for an answer, but I didn't find anything short of using boost which sufficiently answers my question: what is a good way of doing string tokenization (note: I cannot use boost)....
97
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
29
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
16
by: BBM | last post by:
This is so bizarre I hesitate to post it, but I need to get this working. My code looks like this... Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _ " WHERE Scenario =...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
33
by: Jordan Tiona | last post by:
How can I make one of these? I'm trying to get my program to store a string into a variable, but it only stores one line. -- "No eye has seen, no ear has heard, no mind can conceive what God...
4
by: VMI | last post by:
How can I split a string that looks like this: John, Doe, 37282, box 2, 10001, "My description, very important", X, Home If I use String.Split(), it'll split the string that's between the...
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.