9 lines
524 B
Text
9 lines
524 B
Text
define: #haystack -> ('Zig,Zag,Wally,Ronald,Bush,Krusty,Charlie,Bush,Bozo' splitWith: $,).
|
|
{'Washington'. 'Bush'} do: [| :needle |
|
|
(haystack indexOf: needle)
|
|
ifNil: [inform: word ; ' is not in the haystack']
|
|
ifNotNilDo: [| :firstIndex lastIndex |
|
|
inform: word ; ' is in the haystack at index ' ; firstIndex printString.
|
|
lastIndex: (haystack lastIndexOf: word).
|
|
lastIndex isNotNil /\ (lastIndex > firstIndex) ifTrue:
|
|
[inform: 'last occurrence of ' ; word ; ' is at index ' ; lastIndex]]].
|