> I would appreciate some assistance with the following questions:
> 1) Why does an instance of FileStream keep working even after I send a
> close to the instance?
> x:=FileStream readWrite: 'c:\temp.txt'.
> x nextPutAll: 'Hello file'.
> x close.
> x nextPutAll: 'Hello file again'.
> x size.
The file on the file system is closed, but the filestream still exists. You
can check that by looking at the file temp.txt. When the file is open, you
have a pointer from your file stream to that file, and any changes in the
file stream are written to the file at the time you say #close or #flush.
When you close the file (with FileStream>>close), you remove that
connection, but the filestream still exists, so you can still make changes
to that. You have to reconnect the filestream and the file to update the
> 2) What is the best way to add non-printable ASCII characters to a
> string. For example I would like to add CR or LF or ESC.
> For example the following works but it looks convoluted.
> x:='My line has a tab at the end' , (9 asCharacter asString).
Character has a number of class methods; tab, cr, space and so on. So if you
want to add something like that to your stream, you can do it like this:
y := 'Hello'
z := 'there'
a := WriteStream on: String new.
a nextPutAll: y.
a nextPut: Character space.
a nextPutAll: z.
Hope this helps.
> Other languages have shortcuts for some of these characters like \x09
> in C or #09 in Pascal.
> Costas Menico
On Wed, 15 Nov 2000 03:18:53 GMT, [hidden email] (Costas Menico)
>2) What is the best way to add non-printable ASCII characters to a
>string. For example I would like to add CR or LF or ESC.
You might want to add a method similar to
| s i j c |
s := self writeStream.
j := 1.
[(i := self indexOf: $\ startingAt: j) > 0] whileTrue: [
s nextPutAll: (self copyFrom: j to: i - 1).
c := self at: i + 1.
c = $n ifTrue: [s nextPut: Character cr].
c = $t ifTrue: [s nextPut: Character tab].
c = $\ ifTrue: [s nextPut: c].
j := i + 2].
s nextPutAll: (self copyFrom: j to: self size).
^ s contents
to class String. Now you can use
x := '1\n2\n' withEscapes
to assign a string with two cr-terminated lines. The method can
certainly be improved, I just hacked it together in a few minutes.
Stefan Matthias Aust \/ Truth Until Paradox