Home Segments Index Top Previous Next

465: Sidetrip

The simple version of nextNumber shown in Segment 464 is limited, because the numbers read cannot have either a sign or an exponent. You can, however, compose fancier number-reading methods using peek and next to read numbers character by character.

You need to know one trick to handle character-by-character reading. To determine the digit associated with a character, you send the digitValue message to that character, as in the following illustration:

Workspace
Transcript show: $5 printString; cr; 
           show: $5 digitValue printString; cr 
Transcript 
$5 
5