正如标题所示,我不确定检测字符串中是否存在子字符串的最佳途径,例如:
OverExtended:anErrorMessage
"anErrorMessage = 'error: robot arm extended too far' "
(anErrorMessage **contains:** 'extended too far')
ifTrue:[
...
...
]
ifFalse:[
...
...
].
现在我知道上面的方法不起作用,但是是否存在检查子字符串的现有方法?
这可能取决于方言,因此请尝试以下操作
'Smalltalk' includesSubstring: 'mall' --> true
'Smalltalk' includesSubstring: 'malta' --> true
'Smalltalk' indexOfSubCollection: 'mall' --> 2
'Smalltalk' indexOfSubCollection: 'malta' --> 0