Hi Timothy --

Try #upToAnyOf: and CharacterSet such as "Character separators":

'Hello Squeak' readStream upToAnyOf: Character separators.

Best,
Marcel

Am 31.08.2023 09:23:32 schrieb gettimothy <gettimothy@zoho.com>:

Hi Folks.

Is there a standard Stream idiom to get all the data up to a space (or other separator?) 

Here is my motive....


For this simple RosettaCode task  https://rosettacode.org/wiki/A%2BB#Smalltalk

I need to put two numbers on a stream and display their sum on stout

The below works fine for single digit integers.

|task input |
task := [:inStream :outStream |
    |processLine|
    processLine :=
        [
            |a b space outstring|
            a := (inStream next asString).
space := inStream next.
            b :=  (inStream next asString).
            "is validation part of the task?"
            self assert:( a asInteger between:-1000 and: 1000).
            self assert:( b asInteger between:-1000 and: 1000).
outstring := a , ' ' , b , '  ' , ((a asInteger) + (b asInteger)).
outStream store: outstring ; ensureCr; flush.
        ].

    [ inStream atEnd ] whileFalse:processLine.
].

input := Project uiManager request: 'Enter Two Numbers Separated By a Space'.
input isEmptyOrNil ifTrue: [^ self].
task value: input readStream value: (FileStream stdout).

However, I would like to generalize this to handle multi-digit Integers and Real Numbers (i.e. decimal places, not fractions, not e, not i, not square roots, not pi, ...just 123.456  sort of stuff)

I will be adding any answers/solutions to Doc-SqueakHOWTOHelp so I have ready access to this answer when I need it again.


Thanks in advance.