Bug 122521 - JOIN() appends the separator
Summary: JOIN() appends the separator
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
6.1.3.2 release
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-07 04:15 UTC by Bruce Axtens
Modified: 2019-01-07 17:20 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
screenshot (52.26 KB, image/png)
2019-01-07 17:19 UTC, Oliver Brinzing
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bruce Axtens 2019-01-07 04:15:04 UTC
Description:
JOIN() should use the second parameter as a separator rather than as an element terminator. Currently, in Calc macros, the JOIN function returns the array as separator-joined string but with the separator appended. This is a BAD thing.



Steps to Reproduce:
1. Create a macro (in this case called "goofyJoin" and enter the following code
public function goofyJoin(byval R as range) as string
	if not isarray(R) then
		msgbox "no range selected"
		exit function
	end if
	dim result(ubound(R)) as string
	dim c as integer
	c = 0
	dim v as variant
	for each v in R
		result(c) = v
		c=c+1
	next
	dim out as string
	out = join(result,",")
	goofyJoin = out
end function
2. In a spreadsheet, create a range of numbers. 
3. In a nearby cell enter the formula =goofyJoin() and give it the previously defined range and the separator (e.g. ",")


Actual Results:
The range is joined appropriately, but the separator is also appended.

Expected Results:
The range joined with the separator used as a "separator" 


Reproducible: Always


User Profile Reset: No



Additional Info:
Currently I handle this with
	if right(out,1) = "," then
		out = mid(out,1,len(out)-1)
	end if

The issue came up when using Calc to build JSON
Comment 1 Oliver Brinzing 2019-01-07 17:19:52 UTC
Created attachment 148109 [details]
screenshot

IMHO it should work if you use:

> dim result(ubound(R)-1)

please have a look at the attachment - ubound is 4 but array start with 0