TRIM function issue

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

TRIM function issue

Emil Elmarsson
Hello,

I'm not sure where to contact you or if you have an issue tracker
somewhere, so tell me if I should ask this question somewhere else.

I was wondering why your implementation of the Excel TRIM function doesn't
remove extra whitespace, but rather only removes leading and trailing
whitespace like Java's trim function.

Excel: TRIM(" a   b ") -> "a b" (3 characters)
Java: String a = " a   b ".trim(); -> "a   b" (5 characters)

--
Emil Elmarsson
Molnify

molnify.com <http://www.molnify.com/>
linkedin.com/company/molnify <https://www.linkedin.com/company/molnify/>
facebook.com/molnifyapps <https://www.facebook.com/molnifyapps/>
youtube.com/c/molnify <https://www.youtube.com/c/molnify>

Surbrunnsgatan 16 | 114 27 Stockholm | Sweden
+46 (0)76 790 10 44 | [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: TRIM function issue

Nick Burch-2
On Tue, 16 Mar 2021, Emil Elmarsson wrote:
> I'm not sure where to contact you or if you have an issue tracker
> somewhere, so tell me if I should ask this question somewhere else.

Apache POI uses Bugzilla for issue tracking:
https://bz.apache.org/bugzilla/describecomponents.cgi?product=POI

> I was wondering why your implementation of the Excel TRIM function doesn't
> remove extra whitespace, but rather only removes leading and trailing
> whitespace like Java's trim function.

Probably because it's implemented with the Java trim function! :)
https://github.com/apache/poi/blob/trunk/src/java/org/apache/poi/ss/formula/functions/TextFunction.java#L153

> Excel: TRIM(" a   b ") -> "a b" (3 characters)
> Java: String a = " a   b ".trim(); -> "a   b" (5 characters)

If you're able to work up a fix for this, ideally with a unit test that
shows the issue (possibly by adding a few more cells into the TRIM rows in
test-data/spreadsheet/FormulaEvalTestData.xls ?), that'd be great!

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]