I also know that this is more than you intended, but any thought of incorporating the 
split on string into the new StringTokenizer replacement as well?  I think that would 
be pretty useful.  (It's behaviour in two places, but implementation could certainly 
delegate....)

-AMT

-----Original Message-----
From: Al Chou [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 19, 2003 10:22 PM
To: Jakarta Commons Developers List
Subject: [lang] unexpected StringUtils.split behavior (was RE: suggestion for new 
StringUtils.method)


I guess my previous post got lost in the noise, so I'm reposting.  I have two new 
StringUtils.split methods that can split a string at occurrences of a substring rather 
than splitting at the individual characters in the specified delimiter string.

While testing, I discovered that my expectations for the behavior of the split( *, 
..., int max ) methods didn't match their actual behavior.  I expected to get a 
maximum of "max" substrings, all of which were delimited in the parent string by the 
specified delimiters.  Instead, what you get is "max - 1" such substrings, plus the 
rest of the parent string as the final result substring. 
This behavior seems counter to what StringTokenizer would do, which is surprising, 
given the Javadoc comments about using the split methods as alternatives to 
StringTokenizer.

Currently, my tests reflect my expectations for the behavior, and I modified the 
existing split( String, String, int ) method to match my expectations.  I didn't want 
to submit such a change as a proposed patch without first getting feedback from the 
community about whether my expectations are wrong.  I am happy to submit only code 
that does not change the behavior of the existing methods, if need be.


Al


--- Al Chou <[EMAIL PROTECTED]> wrote:
> This thread is a good entree for my question.  I was adding a new 
> StringUtils.split method that can split a string using a whole string 
> as the delimiter, rather than the characters within that string.  In 
> running my JUnit tests, I discovered unexpected behavior in the 
> existing method:
> 
> String stringToSplitOnNulls = "ab   de fg" ;
> String[] splitOnNullExpectedResults = { "ab", "de" } ;
> 
> String[] splitOnNullResults = StringUtils.split( stringToSplitOnNulls, 
> null, 2
> ) ;
> assertEquals( splitOnNullExpectedResults.length, 
> splitOnNullResults.length ) ; for ( int i = 0 ; i < 
> splitOnNullExpectedResults.length ; i+= 1 ) {
>     assertEquals( splitOnNullExpectedResults[i], splitOnNullResults[i] ) ;
> }
> 
> 
> The result of the split call is
> 
> "ab", "de fg"
> 
> and it doesn't look to me like StringTokenizer's documentation implies 
> this behavior....
> 
> 
> Al
> 
> =====
> Albert Davidson Chou
> 
>     Get answers to Mac questions at http://www.Mac-Mgrs.org/ .

=====
Albert Davidson Chou

    Get answers to Mac questions at http://www.Mac-Mgrs.org/ .

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to