gettingstarted
[Top] [All Lists]

How Can I Save the plain ASCII version of Formatted Text?

To: <gettingstarted at lists dot realsoftware dot com>
Subject: How Can I Save the plain ASCII version of Formatted Text?
From: "B Traver" <btraver at traver dot org>
Date: Thu, 23 Sep 2004 21:37:30 -0400
Delivered-to: gettingstarted at lists dot realsoftware dot com
Importance: Normal
Help!  I'm trying to modify the Tutorial text editor program so that I
can save a file as a plain ASCII file rather than as an .rtf file.  (I'm
using Windows.)  Instead of this:

Document.SaveStyledEditField TextField //save the contents of TextField

I tried this:

Dim f as FolderItem
Dim FileStream as TextOutputStream       
f=GetSaveFolderItem("",FileName)
Title=f.Name //window title gets the document name
Filestream = f.CreateTextFile
MsgBox TextField.Text // to try to find out what is being saved to disk
  // but MsgBox doesn't tell the truth!
FIlestream.Write TextField.Text
Filestream.close

What gets saved is still an .rtf file, containing the additional RTF
formatting information.

Hee's a specific example.  MsgBox in the preceding code tells me that
TextField.Text is "Now is the time for all good men" but MsgBox isn't
teling the truth because when Filestream.Write TextField.Text is
performed, this is what is actually written to disk:      

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 MS
Sans Serif;}{\f1\fnil MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;\red255\green0\blue0;}
\viewkind4\uc1\pard\cf1\f0\fs54 Now\fs27  is the \cf2 time\cf1  for \b
all\b0  \i good\i0  \ul men\ulnone .\f1\par
}

In Visual Basic's richtextbox (similar to REALbasic's EditField), it is
easy to distinguish between the plain ASCII text (RichTextBox.Text) and
the Rich Text Format version with the formatting information
(RichTextBox.rtfText), but in RB it seems that TextField.Text seems to
be always the Rich Text Format (sometimes called "StyledText" in RB?),
_except_ when it appears in a MsgBox (for some reason I don't
understand).

If I have some formatted text showing in the EditField control, how do I
save to disk (or otherwise access) the plain ASCII text (e.g., "Now is
the time for all good men") rather all the formatting information along
with it (e.g.,
"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0
MS Sans Serif;}{\f1\fnil MS Sans Serif;}} {\colortbl
;\red0\green0\blue0;\red255\green0\blue0;}
\viewkind4\uc1\pard\cf1\f0\fs54 Now\fs27  is the \cf2 time\cf1  for \b
all\b0  \i good\i0  \ul men\ulnone .\f1\par }")?

Barry Traver

P.S. I even tried changing TextField.Styled to False temporarily, but
what got saved was still the RTF version including formatting
information rather than the plain ASCII text.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>