gettingstarted
[Top] [All Lists]

Re: Create Constant for chr(13) and the like

To: Getting Started <gettingstarted at lists dot realsoftware dot com>
Subject: Re: Create Constant for chr(13) and the like
From: "Joseph J. Strout" <joe at realsoftware dot com>
Date: Wed, 30 Jun 2004 15:21:35 -0500
Delivered-to: gettingstarted at lists dot realsoftware dot com
List-help: <mailto:gettingstarted-request@lists.realsoftware.com?subject=help>
List-id: Getting Started <gettingstarted.lists.realsoftware.com>
List-post: <mailto:gettingstarted@lists.realsoftware.com>
References: <003e01c45ede$238ed390$6501a8c0 at travergateway>
At 4:09 PM -0400 6/30/04, Barry Traver wrote:

QUESTION:  What's the best and/or simplest way to put that information
from the text file into a string array (one line per element) for
manipulation?

Well, there are lots of ways to skin that cat, but here's the simplest:

  Dim inp as TextInputStream
  Dim lines(-1) as String

  inp = theFile.OpenAsTextFile
  lines = Split( inp.ReadAll.Split, EndOfLine )

This assumes that the line endings in the file match the native line endings for the platform. A more robust solution would be this:

  Dim inp as TextInputStream
  Dim lines(-1) as String

  inp = theFile.OpenAsTextFile
  while not inp.EOF
    lines.Append inp.ReadLine
  wend

After I manipulate the string array elements, I should then be able by
myself to concatenate the modified elements (I note that REALbasic uses
"+" rather than "&" for string concatenation) and save the final result
back to disk in the usual way (i.e., Document.SaveStyledEditField in the
tutorial program).

Er... if you have an array of string elements, then SaveStyledEditField is neither useful nor appropriate for saving them to disk. Just make a TextOutputStream, and either write them out line by line using a for loop and WriteLine, or write Join( theArray, EndOfLine ) out all at once.

P.S.  I _am_ working my way through the REALbasic documentation, page by
page, and will have fewer questions as I go along anyway, but I guess
I'm impatient right now and want to port over at least some of my VB
programs as soon as possible.

No worries, that's what the list is for.

Best,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout           REAL Software, Inc.                |
|    joe at realsoftware dot com       http://www.realsoftware.com        |
`------------------------------------------------------------------'
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

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

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