For readability sake I’m going to first state that:
LF = Line Feed CHR(10)
CR = Carriage Return CHR(13)
Since Rich Text Format is a standard formalized by Microsoft Corporation I
get to ask them why they decided that RTF format needed to start writing LF
instead of the CRLF that you see in implemented in non formatted text such as
seen via notepad. Nor can I find any history on why the decision was made.
Was it forgotten and just left behind because RTF knew the formatting and
that was all that mattered? I only find on Google many different people in
many different coding languages trying to deal with the differences. Even on
Microsoft’s site that is all I find.
My main point of interest here is why a Richtextbox.text property would
yield a string that doesn’t fit the plain text standard which ends with CRLF?
And even if this .text property did not provide a way to do that why can't I
find an inherent method that will do this type of conversion? It’s not a
string conversion after all. They are both clearly strings but with a
different choice of line feed. Do I have to write a conversion algorithm
myself? If so, that’s fine. But from all my Google searching I know that I’m
not the first to address this issue.
Why would I want to use an old standard? Well, without a CR your plain text
files look pretty ugly and depending on which programs are trying to read
from these files, they may become dysfunctional after being written from a
Richtextbox if they are expecting CRs. I simply do not want to change the
original format of the files that go through my program and I think that’s a
reasonable request
Using RTF is unavoidable. I need its formatting capabilities to present to
the user the plain text files with highlighted areas of importance. However
when I stuff the contents back into a plain text file, I would like the
formatting to be converted back to plain text and what I mean by that is the
implementation of CRLF instead of just LF.
I am aware of the Richtextbox.Savefile method. However this cannot be used
to set the value to another data structure within memory and has to use the
FSO to store and retrieve the data. This is undesirable for the solution I
need. But this is the only way I currently know of that will do the proper
type of conversion for you.
If somebody can tell me an easy way to accomplish this in VB.net
1: Create a form.
2: Place 1 Pushbutton, 1 Richtextbox and 1 Textbox.
3: Change the properties of the textbox to Multiline = True and WordWrap =
False.
4: Make the boxes big enough to show a few lines of text.
Enter the code for the Click event of Pushbutton: Textbox.text =
Richtextbox.text
Now go run the program and enter in a few lines of data into the RTB and hit
the pushbutton. Watch as the textbox fails to write new lines properly
because there is no CR.
How do I efficiently get around this without reinventing the wheel?