在Smalltalk中,如果给出字符串'OneTwoThree',我想删除最后的'Three'部分,.e.,在Squeak方法查找符号中:'OneTwoThree' . 'Three' . 'OneTwo'.
'OneTwoThree' . 'Three' . 'OneTwo'
我能想到的最好的是:
'OneTwoThree' allButLast: 'Three' size,
'OneTwoThree' allButLast: 'Three' size
但它感觉不太Smalltalk-ish,因为它使用子串长度,而不是子串本身.你会怎么编码?
smalltalk
smalltalk ×1