This recipe is for Dolphin Smalltalk. To run the code, cut and paste it into a workspace and “Evaluate It”

Problem
You want to access or modify just a portion of a string, not the whole thing. For instance, you've read a fixed-width record and want to extract the individual fields.

Solution

| aRecord attributes |

"Create a string to represent customer record"
aRecord := '01 Gary Short 24/01/1970 gary@garyshort.org'.

"Split the record into attributes"
attributes := aRecord subStrings.

"Show the attributes collection in the Transcript window"
Transcript show: attributes printString.

Tag: