Link to home
Start Free TrialLog in
Avatar of jjjkkklll
jjjkkklll

asked on

CStdioFile and carriage returns within a line.

I need to be able to create a text file in Notepad and have my program read the lines from the text file into variables.  Right now I'm using CStdioFile to ReadString the lines into variables and everything is working pretty good.

My question is: is there a way to add something within the line in the text file that would cause a carriage return within that line as it's put into an edit box?  In other words, let's say I have three lines in the text file and when I use ReadString on this file, I load those three lines into separate variables.  Now, within the third string, I want carriage returns to show up in the edit box when I load that string.  I've tried adding \r\n to the line in the text file. I've tried using CFile::typeText as a parameter of CStdioFile.  I've tried replacing \r\n within the resulting CString variable to "\r\n" and other crazy stuff.  So far, I haven't been able to get carriage returns to happen within a line.

Is it possible to add something to a line in a text file that can be read by CStdioFile::ReadString to put carriage returns within that line?  Alternatively, if I can replace, say, "\r\n" with something within the CString variable after loading the line from the text file, what can I put in there to cause a carriage return within the edit box?  I hope this makes sense.  If it doesn't, I'll clarify. Thanks.
Avatar of peterdownes
peterdownes

Have you set the "Want Return" property on the edit box?
Sorry, I mean the "multiline" property.
Avatar of jjjkkklll

ASKER

Yes.
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What do you see when you add the string with the "\r\n" attached to it?
Are you saying that it's all on one line?
I think the fact that I'm loading the CString by using the CStdioFile::ReadString fn is causing the problem.  I've tried a million different versions of \r\n and it always prints within the line inside the box ("Line 1.\r\nLine 2").  I tried adding \n and \r\n to the end of the string before putting it in the box.  I never got this to work.

However, I did find a solution that works for me.  I changed the box to a rich edit control, added the rtf header in front of the string and after and then, when I add \par\par to the text in the text file, it works fine.  It prints with the line breaks within the box.  Why?  Not sure.  No time to figure it out right now.  Thanks everyone for your help.  Not sure who to give the points to.
I'll bet a nickle to a dollar that you are inserting:

     "\\r\\n"

Do I win?

-- Dan
You owe me a nickel.
Then I'll wager a pickle to a lemon, that you inserted a backslash, then inserted an r, etc...  You would need to have a string literal in your ptrogram so that the compiler will convert \r\n into the two desired control characters (0x0d, 0x0a).

>>and it always prints within the line inside the box ("Line 1.\r\nLine 2").

If you see the four literal characters
   \r\n
on the screen, it means that the character \, followed by the character r, followed by the character \, followed by the character n have been inserted into the text.  

If you see two small squares, it means that there are two undisplayable characters (probably CR LF) and the problem is that the display element does not take action (e.g. in a single-line edit control).

-- Dan
>>You would need to have a string literal in your ptrogram so that the compiler will convert \r\n into the
two desired control characters (0x0d, 0x0a).

I think you nailed it on the head, there. My next try would've to put something like ~~ anywhere I wanted a line break and them do a CString replace, replacing that with \r\n, but I've moved on.  Thanks for the help, Dan.  And keep your pickle.