visualworks smalltalk:如何从字符串中检测子字符串,有可能吗?

问题描述 投票:0回答:1

正如标题所示,我不确定检测字符串中是否存在子字符串的最佳途径,例如:

OverExtended:anErrorMessage

"anErrorMessage = 'error: robot arm extended too far' "

(anErrorMessage **contains:** 'extended too far')
ifTrue:[
   ...
   ...
]
ifFalse:[
   ...
   ...
].

现在我知道上面的方法不起作用,但是是否存在检查子字符串的现有方法?

string substring smalltalk visualworks
1个回答
0
投票

这可能取决于方言,因此请尝试以下操作

'Smalltalk' includesSubstring: 'mall' --> true
'Smalltalk' includesSubstring: 'malta' --> true

'Smalltalk' indexOfSubCollection: 'mall' --> 2
'Smalltalk' indexOfSubCollection: 'malta' --> 0
© www.soinside.com 2019 - 2024. All rights reserved.