RosettaCodeData/Task/Search-a-list/Smalltalk/search-a-list-1.st
2023-07-01 13:44:08 -04:00

15 lines
577 B
Smalltalk

| haystack |
haystack := 'Zig,Zag,Wally,Ronald,Bush,Krusty,Charlie,Bush,Bozo' subStrings: $,.
{ 'Washington' . 'Bush' } do: [:word |
|t|
((t := haystack indexOf: word) = 0)
ifTrue: [ ('%1 is not in the haystack' % { word }) displayNl ]
ifFalse: [
|l|
('%1 is at index %2' % { word . t }) displayNl.
l := ( (haystack size) - (haystack reverse indexOf: word) + 1 ).
( t = l ) ifFalse: [
('last occurence of %1 is at index %2' % { word . l }) displayNl ]
]
].