Hi everyone, I have a stream (read from a file) and i want to iterate through it in order to replace every occurences of a special character by another one. how can i do it ? -- Kenfack Valmy-Roi Ingénieur des travaux en Informatique de Gestion/ Analyste Programmeur Elève ingénieur de conception en génie logiciel Institut Supérieur du Sahel Email : roykenvalmy@gmail.com Tel: +237 22 11 01 87/ +237 676 94 23 01 / +237 699 04 0612
Hi, You can do it by using on a subclass of WriteStream "peek" and "nextPut:" methods. Or you can transform the stream into a Collection by using "contents" and do almost everything you want. Cheers, Vincent -----Message d'origine----- De : Pharo-dev [mailto:pharo-dev-bounces@lists.pharo.org] De la part de valmy roi Envoyé : samedi 16 mai 2015 07:48 à : pharo-dev@lists.pharo.org Objet : [Pharo-dev] Usage of stream Hi everyone, I have a stream (read from a file) and i want to iterate through it in order to replace every occurences of a special character by another one. how can i do it ? -- Kenfack Valmy-Roi Ingénieur des travaux en Informatique de Gestion/ Analyste Programmeur Elève ingénieur de conception en génie logiciel Institut Supérieur du Sahel Email : roykenvalmy@gmail.com Tel: +237 22 11 01 87/ +237 676 94 23 01 / +237 699 04 0612
Do you have to modify the file? Create a new file with the modifications? Or get the file in memory but modified? On Sat, May 16, 2015 at 6:05 AM, Vincent BLONDEAU < vincent.blondeau@polytech-lille.net> wrote:
Hi,
You can do it by using on a subclass of WriteStream "peek" and "nextPut:" methods. Or you can transform the stream into a Collection by using "contents" and do almost everything you want.
Cheers, Vincent
-----Message d'origine----- De : Pharo-dev [mailto:pharo-dev-bounces@lists.pharo.org] De la part de valmy roi Envoyé : samedi 16 mai 2015 07:48 à : pharo-dev@lists.pharo.org Objet : [Pharo-dev] Usage of stream
Hi everyone, I have a stream (read from a file) and i want to iterate through it in order to replace every occurences of a special character by another one. how can i do it ?
-- Kenfack Valmy-Roi Ingénieur des travaux en Informatique de Gestion/ Analyste Programmeur Elève ingénieur de conception en génie logiciel Institut Supérieur du Sahel Email : roykenvalmy@gmail.com Tel: +237 22 11 01 87/ +237 676 94 23 01 / +237 699 04 0612
Yes, i have to create a new file fith the modifications. All what i've done for now is to copy the content of the original file in a stream and paste it in the new file, without any mofication Le 16 mai 2015 10:09, "Sergio Fedi" <sergio.fedi@gmail.com> a écrit :
Do you have to modify the file? Create a new file with the modifications? Or get the file in memory but modified?
On Sat, May 16, 2015 at 6:05 AM, Vincent BLONDEAU < vincent.blondeau@polytech-lille.net> wrote:
Hi,
You can do it by using on a subclass of WriteStream "peek" and "nextPut:" methods. Or you can transform the stream into a Collection by using "contents" and do almost everything you want.
Cheers, Vincent
-----Message d'origine----- De : Pharo-dev [mailto:pharo-dev-bounces@lists.pharo.org] De la part de valmy roi Envoyé : samedi 16 mai 2015 07:48 à : pharo-dev@lists.pharo.org Objet : [Pharo-dev] Usage of stream
Hi everyone, I have a stream (read from a file) and i want to iterate through it in order to replace every occurences of a special character by another one. how can i do it ?
-- Kenfack Valmy-Roi Ingénieur des travaux en Informatique de Gestion/ Analyste Programmeur Elève ingénieur de conception en génie logiciel Institut Supérieur du Sahel Email : roykenvalmy@gmail.com Tel: +237 22 11 01 87/ +237 676 94 23 01 / +237 699 04 0612
Maybe you should open a stream reading the original file the open a writing stream for the copy file And reading from one, writing on the other, replacing what you need in the intermediate collection of bytes/characters â
that is my problem, replacing the character with another one, how can i do it? 2015-05-16 11:28 UTC+01:00, Sergio Fedi <sergio.fedi@gmail.com>:
Maybe you should open a stream reading the original file the open a writing stream for the copy file And reading from one, writing on the other, replacing what you need in the intermediate collection of bytes/characters â
-- Kenfack Valmy-Roi Ingénieur des travaux en Informatique de Gestion/ Analyste Programmeur Elève ingénieur de conception en génie logiciel Institut Supérieur du Sahel Email : roykenvalmy@gmail.com Tel: +237 22 11 01 87/ +237 676 94 23 01 / +237 699 04 0612
Well, when retrieving some bytes from the read stream you will have them, temporarily, in a collection (OrderedCollection or Array I assume) With that you can use the messages from those collections: 'a3a' copyReplaceAll: '3' with: 'R' âWhich gives 'aRa'
To replace all X's in input.txt with Y's in output.txt, you can do: 'input.txt' asFileReference readStreamDo: [ :in | 'output.txt' asFileReference writeStreamDo: [ :out | [ in atEnd ] whileFalse: [ | ch | (ch := in read) = $X ifTrue: [ out nextPut: $Y ] ifFalse: [ out nextPut: ch ] ] ] ].
On 16 May 2015, at 18:56, valmy roi <roykenvalmy@gmail.com> wrote:
that is my problem, replacing the character with another one, how can i do it?
2015-05-16 11:28 UTC+01:00, Sergio Fedi <sergio.fedi@gmail.com>:
Maybe you should open a stream reading the original file the open a writing stream for the copy file And reading from one, writing on the other, replacing what you need in the intermediate collection of bytes/characters â
-- Kenfack Valmy-Roi Ingénieur des travaux en Informatique de Gestion/ Analyste Programmeur Elève ingénieur de conception en génie logiciel Institut Supérieur du Sahel Email : roykenvalmy@gmail.com Tel: +237 22 11 01 87/ +237 676 94 23 01 / +237 699 04 0612
If you want to convert character encoding, read the chapter of Zinc on encodings https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/ws/Zinc-Encod... Le 16/5/15 07:48, valmy roi a écrit :
Hi everyone, I have a stream (read from a file) and i want to iterate through it in order to replace every occurences of a special character by another one. how can i do it ?
participants (5)
-
Sergio Fedi -
stepharo -
Sven Van Caekenberghe -
valmy roi -
Vincent BLONDEAU