Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Malfunction of "string trimright" with certain strings

Closed / Invalid2845214fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2009-08-26 22:27:04
The following script produces incorrect output for "stringb":
set stringa "teststring_a.pdb"
set stringb "teststring_b.pdb"
set outa [string trimright $stringa ".pdb"]
set outb [string trimright $stringb ".pdb"]
puts "$stringa -> $outa"
puts "$stringb -> $outb"

With several recent Tcl versions, I get this output:
teststring_a.pdb -> teststring_a
teststring_b.pdb -> teststring_

I would instead, expect this output to be correct:
teststring_a.pdb -> teststring_a
teststring_b.pdb -> teststring_b
andreas_kupriesplain2009-08-27 05:39:08
No, this is not a bug.

The string ".pdb" is not removed as a string. It is interpreted as a 'set of characters', and all characters in that set are removed. In your example the set contains the four characters {'.' 'p' 'd' 'b'}. Note the 'b'.

And for "teststring_b.pdb" trimgright correctly removes the 'b' just before the underscore.

Note the phrasing in the manpage (http://docs.activestate.com/activetcl/8.5/tcl/TclCmd/string.htm#M54):
 ... any trailing characters present in the string given by chars ...
i.e. ... any ... character ... present in ... chars
andreas_kupriesplain2009-08-27 05:39:14
allow_comments - 1
Log in (anonymous is fine) to add a comment.