You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <gg...@seagullsw.com> on 2003/10/08 20:42:53 UTC

[lang] StringUtils.substringAfter()

Hello,

I find the current behavior of StringUtils.substringAfter() not quite right
for my needs. For example, I want to strip the leading 'www.' in a host
string. If the search string is not there, the empty string is returned,
which force me to write:

String host = ...
String strippedHost = StringUtils.substringAfter(host, "www.");
if (StringUtils.isEmpty(strippedHost)) {
   strippedHost = host;
}
//continue with stripped host.

Instead of:

String host = ...
String host = StringUtils.substringAfter(host, "www.");
//continue with stripped host.

If the API returned the its argument instead of "".

You'd think stripStart would do this but stripStart works on a character
set, not a string prefix.

So:

(1) I do not thing that changing the current API is nice.

(2) Does this case warrant a new API? Or is this case really unusual?
New API: stripStartString(String, String)
Perhaps rename (deprecate etc) startStart to startStartCharSet?

Thanks,
Gary