ABSOLUTE BEGINNER
Your First Prefix Test in Squeak
Ask if a piece of text starts with a few letters, in five tiny Workspace steps.
STEP 1
Ask if the start matches
In Workspace, select the whole line and choose Print it. Squeak checks only the start.
'Squeak' beginsWith: 'Squ'
The first three letters match, so the answer is true.
STEP 2
Find a word in the middle
Shell appears later. This question does not search the entire text.
'sea shell' beginsWith: 'shell'
The answer is false because the text starts with sea.
STEP 3
Start with the first word
Change the text after the colon to the first word.
'sea shell' beginsWith: 'sea'
The answer changes to true.
STEP 4
Change the capital letter
Capital S and small s are different letters for this check.
'Squeak' beginsWith: 'squ'
The answer is false.
STEP 5
Match the whole word
The starting text can be as long as the whole string.
'tea' beginsWith: 'tea'
The exact match also answers true.
YOU DID IT
A small step. A real result.
beginsWith: answers true only when the requested text is at the start. It compares case exactly.
Optional code download: open it as text and copy one example into Workspace.