Smalltalk writes a sorted collection to a file

let's say I have a SortedCollection called whitepages, each record contains Customervalues ​​with nameand number. I want to create a function that writes them to a file this way

name1 
number1 
name2
number2

I must admit that I am completely stuck here. Can anyone help?

+2
source share
1 answer

Ok, hope you know how to write to a file. And since you noticed that you sorted the collection, I suppose you are Customerordered the way you want.

Then what can you do:

(whitepages collect: [ :customer |
  customer name,
  Character cr asString,
  customer number ]) joinUsing: Character cr

, . , name number , asString .

- - :

whitepages do: [ :customer |
  stream
    nextPutAll: customer name;
    cr;
    nextPutAll: customer number;
    cr ]

stream - .

+6

Source: https://habr.com/ru/post/1623769/


All Articles