commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] [Resolved] (LANG-811) StringUtils.stripStart strips out too many characters
Date Tue, 10 Jul 2012 16:01:35 GMT


Sebb resolved LANG-811.

    Resolution: Invalid

>From the Javadoc for stripStart():

Strips any of a *set* of characters from the start of a String.

It treats the "Tag-" as the set of characters 'T' 'a' 'g' '-' and removes any it finds from
the start of the the string. 'T' appears twice, so is removed both times.
> StringUtils.stripStart strips out too many characters 
> ------------------------------------------------------
>                 Key: LANG-811
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 2.5, 2.6, 3.0, 3.1
>         Environment: N/A
>            Reporter: Chris Kelly
>              Labels: api-change
> I have a String "Tag-TransactionId" for which I want to remove the leading "Tag-" leaving
only "TransactionId". I thought I could use StringUtils.stripStart for this but when I do
I get the string "ransactionId" instead. 
> Below is a short method indicating the issue. 
>  public static void main(String[] args) {
>         String key = "Tag-TransactionId";
>         String keyWithoutTag = StringUtils.stripStart(key, "Tag-");
>         String expected = "TransactionId";
>         System.out.println("Expected: " + expected + " but got: " + keyWithoutTag);
>     }
> I have tried repeating test on commons-lang from 2.5 upwards to the latest release all
with the same behaviour. It looks like if the string to be removed has characters similar
to the remaining string, the stripStart methods works incorrectly. It seems to be a case problem
as well. If I use "Tag-transactionId" with stripStart it successfully returns "transactionId"

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message