From: Jeff H. <jeffh@ActiveState.com> - 2005-07-07 02:14:12
|
> While we're talking about 'string' command options, can I propose two > new ones: > > 'string insert string /index/ /string2/' : inserts string2 at Yes, this would be useful. > 'string endswith /string1/ /string2/' : there is no need for a > 'startswith' because you can use [string first s1 s2] == 0, > but to check > if a string ends with a particular substring currently > requires the use > of [string length] and [string first] (or last), again causing > non-obvious code. Returns 1 (true) or 0 (false). Errr ... 'string match *end "startfoobarend"' => 1. The string match does have the implicit anchoring, so I don't think you need endswith. Note that I would most certainly write string match star* $str over [string first $s1 $s2] == 0 in my own coding. I assume you are worried about patterns that use a var that may have glob-sensitive chars? Jeff |