473,402 Members | 2,053 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,402 software developers and data experts.

RichTextFormat to PlainText

I have been working on a project to Search and Replace text within files. The
project includes automatic file backups and date by date file restores. I use
a richtextbox to display the text with color formatting where search strings
have been found. This way I can highlight multiple search finds at the same
time, unlike a textbox.
To be efficient I load the files that have found strings into an array and
display the names of these files in a listbox. Once the listbox is clicked
the file loads from the appropriate index in the array into the richtextbox
and formats the text where strings have been found. If any changes are made
to the richtextbox via the automatic replace or a manual change they are
saved back to the array and marked as changed so that they can be saved back
to the file when the users chooses. Importantly they are saved back to the
array as richtext and no longer plain text and thus the problem arises.
I am aware that richtextboxes have a savefile function that allows them to
save their info as PlainText but this seems to be the ONLY way to get data
out of them as plain text and I don’t want to rush the user to save each file
as they make changes. Also I think that it is inefficient to load the array
back into the richtextbox for each file as the save process is completed when
there could be potentially hundreds of files to be saved. For the same reason
I’m not sure opening hundreds of child forms would be any better. I'm trying
to avoid using too much resources but I have found no other way to get
richtextformat to save as plain text without the funky formatting. Of course
convert types do no address this matter since being richtextformat is not an
argument of being a string or not.

I have seen other control types that can do much more sophisticated
highlights than even a richtextbox has to offer. For example just bring up a
found search topic in .net and you will see highlighted text etc. I've
attempted to set something up via HTML but I'm not too savvy with that and
after a futile attempt thought that I might ask here before investing loads
of time researching if HTML was even the way to go. After all my interface
must be able to accept changes by the user and convert that back to plain
text without any formatting of any kind introduced to the file.

I'm just a sole developer lost in the universe of .net
Somebody please help. There has to be a better solution to this problem.

Apr 3 '06 #1
5 1191
Hello, AWenser,

Re: "Importantly they are saved back to the array as richtext and no
longer plain text and thus the problem arises."

I don't understand why you need to do this. Why not just save them back
to the array using the Text property?

Cheers,
Randy
AWesner wrote:
I have been working on a project to Search and Replace text within files. The
project includes automatic file backups and date by date file restores. I use
a richtextbox to display the text with color formatting where search strings
have been found. This way I can highlight multiple search finds at the same
time, unlike a textbox.
To be efficient I load the files that have found strings into an array and
display the names of these files in a listbox. Once the listbox is clicked
the file loads from the appropriate index in the array into the richtextbox
and formats the text where strings have been found. If any changes are made
to the richtextbox via the automatic replace or a manual change they are
saved back to the array and marked as changed so that they can be saved back
to the file when the users chooses. Importantly they are saved back to the
array as richtext and no longer plain text and thus the problem arises.
I am aware that richtextboxes have a savefile function that allows them to
save their info as PlainText but this seems to be the ONLY way to get data
out of them as plain text and I don’t want to rush the user to save each file
as they make changes. Also I think that it is inefficient to load the array
back into the richtextbox for each file as the save process is completed when
there could be potentially hundreds of files to be saved. For the same reason
I’m not sure opening hundreds of child forms would be any better. I'm trying
to avoid using too much resources but I have found no other way to get
richtextformat to save as plain text without the funky formatting. Of course
convert types do no address this matter since being richtextformat is not an
argument of being a string or not.

I have seen other control types that can do much more sophisticated
highlights than even a richtextbox has to offer. For example just bring up a
found search topic in .net and you will see highlighted text etc. I've
attempted to set something up via HTML but I'm not too savvy with that and
after a futile attempt thought that I might ask here before investing loads
of time researching if HTML was even the way to go. After all my interface
must be able to accept changes by the user and convert that back to plain
text without any formatting of any kind introduced to the file.

I'm just a sole developer lost in the universe of .net
Somebody please help. There has to be a better solution to this problem.

Apr 4 '06 #2
If you mean that I should set my array value to the richtextbox.text property
that is what I am doing. Rich text format is still concidered text however.

arrFile(2, iSelect) = rtbFound.Text
Perhaps I should be formatting my array differently? It holds various data
like the file path as string, file data as string, isEdited as boolean.
"R. MacDonald" wrote:
Hello, AWenser,

Re: "Importantly they are saved back to the array as richtext and no
longer plain text and thus the problem arises."

I don't understand why you need to do this. Why not just save them back
to the array using the Text property?

Cheers,
Randy
AWesner wrote:
I have been working on a project to Search and Replace text within files. The
project includes automatic file backups and date by date file restores. I use
a richtextbox to display the text with color formatting where search strings
have been found. This way I can highlight multiple search finds at the same
time, unlike a textbox.
To be efficient I load the files that have found strings into an array and
display the names of these files in a listbox. Once the listbox is clicked
the file loads from the appropriate index in the array into the richtextbox
and formats the text where strings have been found. If any changes are made
to the richtextbox via the automatic replace or a manual change they are
saved back to the array and marked as changed so that they can be saved back
to the file when the users chooses. Importantly they are saved back to the
array as richtext and no longer plain text and thus the problem arises.
I am aware that richtextboxes have a savefile function that allows them to
save their info as PlainText but this seems to be the ONLY way to get data
out of them as plain text and I don’t want to rush the user to save each file
as they make changes. Also I think that it is inefficient to load the array
back into the richtextbox for each file as the save process is completed when
there could be potentially hundreds of files to be saved. For the same reason
I’m not sure opening hundreds of child forms would be any better. I'm trying
to avoid using too much resources but I have found no other way to get
richtextformat to save as plain text without the funky formatting. Of course
convert types do no address this matter since being richtextformat is not an
argument of being a string or not.

I have seen other control types that can do much more sophisticated
highlights than even a richtextbox has to offer. For example just bring up a
found search topic in .net and you will see highlighted text etc. I've
attempted to set something up via HTML but I'm not too savvy with that and
after a futile attempt thought that I might ask here before investing loads
of time researching if HTML was even the way to go. After all my interface
must be able to accept changes by the user and convert that back to plain
text without any formatting of any kind introduced to the file.

I'm just a sole developer lost in the universe of .net
Somebody please help. There has to be a better solution to this problem.

Apr 4 '06 #3
Hi,

AFAIK, the Text property of a RichTextBox doesn't output RichText, it
simply returns the text without the RTF codes. The RTF property is the
one that should return the text *with* the RTF codes. I think that's
what Randy was questioning, as well.

So, how are you determining that the data is saved to the array as
RichText and not simple text ?

Regards,

Cerebrus.

Apr 4 '06 #4
I have determined that the text has changed by several different methods:
1: just after loading the rtf box with the string from the array I find that
the .text.compare property finds these two strings different. it has already
changed the text in the control without any user intervention. also if you
place a break here and watch the two strings before and after you will see
they are a different length because of the RTF formatting.
2: by opening a writestream and saving this data in the array to the file. I
have tried using many different commands and properties to write to a file
but they all turn out with the same result to me. The first thing you will
see are square ascii characters where the carraige return used to be. Also
when testing you need to open up in Notepad or something else that does not
support RTF or you will not see the anomaly.

I have observed that this happens on edited text within the rich text box.
It does not overwrite with different ascii codes in this pattern when the
text is unmodified.

If you are curious to see then you can make a simple version of this by
creating a form with a richtextbox. Use the FSO to write from the control to
the file as this is the preffered method for me. Using the rtf.SaveFile(as
plaintext) property is a last resort and I am trying to figure out how not to
use that.

For clarification I have never used the .rtf property.

Thank you for the replies.

"Cerebrus" wrote:
Hi,

AFAIK, the Text property of a RichTextBox doesn't output RichText, it
simply returns the text without the RTF codes. The RTF property is the
one that should return the text *with* the RTF codes. I think that's
what Randy was questioning, as well.

So, how are you determining that the data is saved to the array as
RichText and not simple text ?

Regards,

Cerebrus.

Apr 4 '06 #5
It doesn't appear that anyone has an answer readily available for this quirky
little problem or why. I know the basic concept of how RTF works and I know
that it is placing a few different characters that an RTF reader understands
as carraige returns, but I don't know enough to try to create my own
algorithm to replace these RTF style carraige return characters with the
plain text style characters. I would rather not assume since everyone knows
what kinds of trouble that can lead to.

I've had the idea that since .savedata(as plaintext) does work, meaning it
doesn't leave those lovely ascii characters in my text files and as long as I
still have the changed data in the richtextbox before I unload it, I will
have the richtextbox perform its savedata function and make a temporary file
for each edited file and place them in the base application folder. Then when
the user comfirms that all changes are to be saved these files can be
reloaded back into the array and I can continue through my savetime
enumeration. Otherwise I'll discard them. Symptoms solved, however the true
cause is not...
Apr 5 '06 #6

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

Similar topics

6
by: LRW | last post by:
Because I've had recipients of our newsletter tell us they can't (or won't) receive HTML e-mail, I found out how to make an e-mail that sends both HTML and a plaintext version in a multipart...
7
by: news | last post by:
Before I begin, I realise there's a big war regarding HTML in e-mails. Personally, I don't like it. Unfortunately, I'm being paid by my company to create an automated newsletter for our customers....
5
by: Ajay Brar | last post by:
hi! I am getting an error - Crypto.PublicKey.RSA.error: Plaintext too large - when verifying the signature of a document. What i am doing is - the document and the signature are downloaded off...
8
by: Dave Smithz | last post by:
Hi, Thanks to this group I discovered the excellent PHP Mailer (http://phpmailer.sourceforge.net/) which I use to send emails. Part of my application emails out hundreds of club members unique...
6
by: Joerg Battermann | last post by:
Hey there, mmmm does anyone know a library or anything I can use to convert plaintext to html real quick and vice-versa? Regex surely would do the trick to a certain level, but maybe there's...
1
by: simon | last post by:
I have an unbound RTF2 control in an Access 2003 form which I set to show either unformatted text or else text with words and sentences highlighted. I do this by setting the PlainText property,...
2
by: genojoe | last post by:
I created a document in Word and saved it in RTF format. The document consists of a title line, and two text lines. For the two text lines I did paragraph spacing of 0 points before and 6 points...
7
by: Luca Villa | last post by:
I have many html files named like these: c:\dir\femo-black.html c:\dir\loren-white.html c:\dir\spark-white.html c:\dir\kim-black.html c:\dir\paul-white.html How can I convert only the files...
5
Tarantulus
by: Tarantulus | last post by:
Hi All, I have what I believe is a complex problem, but hopefully you'll be able to provide me with a simple answer. I'm using XMLHttpRequest() to call a PHP script (which I have no control...
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.