How do I put escape codes in a text file read by wxtextfile?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
davidlondonuk
In need of some credit
In need of some credit
Posts: 8
Joined: Mon May 21, 2018 6:58 am

How do I put escape codes in a text file read by wxtextfile?

Post by davidlondonuk » Sun Jul 22, 2018 9:14 am

Hi,

I'm writing a flash-card program using wxtextfile to read in questions and answers(each on a line) - this is output to a textctrl. My problem is I can't find a way to format the text, whatever I put in the text file is output, as is, to the textctrl e.g if I put an escape code like "\n" in the file to get a new line I get \n in the textctrl as text instead.

I want to be able to have new paragraphs and italics in the text that gets read from the file, I just can't see how to format the text that gets displayed in the textctrl.

Thanks for any help.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2065
Joined: Sun Jan 03, 2010 5:45 pm

Re: How do I put escape codes in a text file read by wxtextfile?

Post by PB » Sun Jul 22, 2018 10:13 am

You seem to mix two different things, C++ escape codes (end of the lines) and formatting (bold, italics)?

If you write "\n" to a C++ string in code, it gets translated to a actual platform dependent end of the line characters. I.e, if you create a string like this

Code: Select all

wxString s = "Question\nAnswer";
and write it to a text file, it will contain two words separated by new a line.

If the file really contains literal "\n" text, then it gets read into a string as it is, no translation to C++ escape code is being done.

Text formatting in the wxTextCtrl is achieved by applying wxTextAtrr.

Perhaps you could look into wxRichTextCtrl, this control can save and load formatted text (in its own XML-based format).

davidlondonuk
In need of some credit
In need of some credit
Posts: 8
Joined: Mon May 21, 2018 6:58 am

Re: How do I put escape codes in a text file read by wxtextfile?

Post by davidlondonuk » Mon Jul 23, 2018 10:58 am

Thanks for that.
As wxtextfile reads in text as wxstrings, I assumed escape codes would work - which they do, but not from a file.

I have to code an edit dialog so rich text is the way to go. C++ escapes was the simplest solution, but ultimately too simple.

Post Reply