473,383 Members | 1,876 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,383 software developers and data experts.

Frustrations with RTF format.

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?

Apr 6 '06 #1
4 6493
I am not sure what you are trying to accomplish here. If you want to use an
RTF control to get all your formatting and stuff then why are you trying to
display that text in a plain text box and expect it to look anything like
the RTF formatted document. Open a MS Word doc in Notepad and see what you
get. If you want to get the data out of Word into a plain text file you need
to do a Save As and select a different file type that invariably takes a
different code path and saves the text as raw ASCII. Doing this even brings
up a dialog box that allows you to pick the formatting that you want to use
for that plain text document. It lets you sent the encoding to use, the
ability to insert line breaks, to end lines with CR\LF - LF\CR - CR Only -
LF Only, and even to do character substitution.

I would suggest that things are not as 'standard' as you had hoped but there
is no doubt that RTF in and of itself is a standard and so is ASCII text.
You can't compare the two as apples-to-apples and clearly converting between
them is going to take some wheel inventing to get done what you want.
"AWesner" <AW*****@discussions.microsoft.com> wrote in message
news:AA**********************************@microsof t.com...
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?

Apr 6 '06 #2
Thank you for your response.

"I am not sure what you are trying to accomplish here. If you want to use an
RTF control to get all your formatting and stuff then why are you trying to
display that text in a plain text box and expect it to look anything like
the RTF formatted document. Open a MS Word doc in Notepad and see what you
get."

My example of loading text from an RTF to text is the opposite of what you
are expecting here. My goal is to use the RTF to highlight text but I wanted
it to lose all formatting when it reached the text box. And so far, except
the CR this is true.

I admit that using a Richtextbox for what I am trying to accomplish may not
be the correct solution. But at the moment I am uneducated as to what would
be better to display multiple highlighted text.

What I am trying to do is load many, possibly hundreds, of text files into
an array for search and replace purposes. The search procedure runs through
these files finding and highlighting search strings so that it is easier on
the user to see where the subject string(s) is/are located. Each file that is
changed whether manually or programatically is marked as being changed so
that it can be saved at a later time.

"If you want to get the data out of Word into a plain text file you need
to do a Save As and select a different file type that invariably takes a
different code path and saves the text as raw ASCII. Doing this even brings
up a dialog box that allows you to pick the formatting that you want to use
for that plain text document. It lets you sent the encoding to use, the
ability to insert line breaks, to end lines with CR\LF - LF\CR - CR Only -
LF Only, and even to do character substitution."

Both of the facts that each file already has its path set and that there are
hundreds of these waiting to be saved has detered me from bugging the user
with a savedialog. I have looked into the savedialog help file to see if I
could catch a glimpse of some code example showing plain text files being
saved but I never did. My best efforts so far were to use the FSO in various
methods to try to write in ANY format available to see if it changed the text
file result, including ASCII. It didnt. But as you point out I was not using
the Savedialog formats. I will give this further investigation since you
brought it up and see if I can't skip the dialog popup but use it's format.

Thanks
Apr 7 '06 #3
AWesner wrote:

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?


Do the following in your Button Click Event -

TextBox1.Text = RichTextBox1.Text.Replace(ChrW(10), vbCrLf)

Regards,

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Apr 7 '06 #4
Simple and effective. For my purposes this works very well.

Thanks

"ShaneO" wrote:
AWesner wrote:

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?


Do the following in your Button Click Event -

TextBox1.Text = RichTextBox1.Text.Replace(ChrW(10), vbCrLf)

Regards,

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

Apr 7 '06 #5

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

Similar topics

3
by: Lowell Kirsh | last post by:
In Peter Norvig's Infrequently Answered Questions he explains that the following 2 fnctions look almost identical but are not the same: def printf(format, *args): print format % args, def...
15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
3
by: stevek | last post by:
How do I format an integer. Add commas. 1234565 1,234,565 TIA
6
by: Dario Di Bella | last post by:
Hi all, we have the following urgent issue affecting our development team. Initially we had one particular workstation that failed executing queries on a DB2 database, raising an invalid date...
3
by: Melissa | last post by:
What specifically causes the Format event of a report's section to fire? Thanks! Melissa
11
by: Grumble | last post by:
Hello, I have the following structure: struct foo { char *format; /* format string to be used with printf() */ int nparm; /* number of %d specifiers in the format string */ /* 0 <= nparm <=...
4
by: David Morris | last post by:
Hi Could somebody please explain what the following line of code means String.Format("{0}\{1}.{2:00}", C:\, myfile.txt, 1 It's actually the first argument that I don't understand. What is...
13
by: Roy | last post by:
Hi all, I'm creating a project that should always use this date format when displays the dates or create dates. The back end database is a SQL Server and I like to know what is the logical way...
3
by: Carl Trachte | last post by:
Hello. Python 3.0.a1 has been released. I'm trying to get the hang of the new string formatting in the form: '5.66' There are more options in PEP 3101 (fill, alignment, etc.), but I'm having...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.