ggregory 2003/10/28 17:49:47 Modified: lang/src/java/org/apache/commons/lang StringUtils.java Log: Added public static String removeStart(String str, String remove). Revision Changes Path 1.113 +36 -1 jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java Index: StringUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v retrieving revision 1.112 retrieving revision 1.113 diff -u -r1.112 -r1.113 --- StringUtils.java 23 Oct 2003 20:49:22 -0000 1.112 +++ StringUtils.java 29 Oct 2003 01:49:47 -0000 1.113 @@ -4353,4 +4353,39 @@ return a; } + /** + * <p>Removes a substring only if it is at the begining of a source string, otherwise returns the source string. + * + * <p>A <code>null</code> source string will return <code>null</code>. + * An empty ("") source string will return the empty string. + * A <code>null</code> search string will return the source string.</p> + * + * <pre> + * StringUtils.removeStart(null, *) = null + * StringUtils.removeStart("", *) = "" + * StringUtils.removeStart(*, null) = * + * StringUtils.removeStart("www.domain.com", "www.") = "domain.com" + * StringUtils.removeStart("domain.com", "www.") = "domain.com" + * StringUtils.removeStart("abc", "") = "abc" + * </pre> + * + * @param string the source String to search, may be null + * @param remove the String to search for, may be null + * @return the substring after the optional occurrence of the separator, + * <code>null</code> if null String input + */ + public static String removeStart(String str, String remove) { + if (str == null || str.length() == 0) { + return str; + } + if (remove == null || remove.length() == 0) { + return str; + } + int pos = str.indexOf(remove); + if (pos == -1) { + return str; + } + return str.substring(pos + remove.length()); + } + }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]