Page 1 of 1

A TEXTSPLIT function

Posted: Thu Jul 25, 2024 11:57 pm
by Lupp
LibreOffice Calc has a working TEXTJOIN() function since V 4.4. V 5.4.
===EDIT 2024-07-27===
Thanks to @cwolan for the correction.
===/EDIT ===
A counterpart is still missing.
(AOO has no TEXTJOIN(), and consequently no reverting function.)

Code: Select all

REM  *****  BASIC  *****

Option Explicit

REM A simple version. The returned result is a sequence of stings.
REM Using the function in Calc with forced array evaluation it will go to a cell strip.

Function udfTextSplitStrip(pSeparator As String, pOmitEmpty As Boolean, pWorkString, Optional pMinLength As Long)
Dim wSequ, u As Long, m As Long, n As Long, j As Long, j_ele As String
If IsMissing(pMinLength) Then pMinLength  = 0
wSequ       = Split(pWorkString, pSeparator)
u           = Ubound(wSequ)
n           = -1
For j = 0 To u
 j_ele       = wSequ(j)
  If (j_ele<>"") OR NOT pOmitEmpty Then
   n          = n + 1
   wSequ(n)   = j_ele
  EndIf
Next j
m             = IIf(n<(pMinLength - 1), pMinLength - 1, n)
If m>=0 Then
 Redim Preserve wSequ(m)
 For j = n + 1 To m
  wSequ(j)   = ""
 Next j
EndIf
udfTextSplitStrip = wSequ
End Function
can do the split.
Used for direct output to a spreadsheet the function will only make sense if array-mode is forced.
It will then lock an output range. To get a kind of relief for the problem with array output of variable length it has a parameter allowing to set a minimal length. Currently unneeded cells at the end will then get the empty string. Overflow may occur, of course.
A little demo:
splitExperiment.ods
(17.94 KiB) Downloaded 242 times

Re: A TEXTSPLIT function

Posted: Sat Jul 27, 2024 7:44 am
by cwolan
Thanks for the macro and little demo.


The sentence in the first REM sounds a bit ominous (or promising if you like).

Lupp wrote: Thu Jul 25, 2024 11:57 pm LibreOffice Calc has a working TEXTJOIN() function since V 4.4.

Comment no. 6 to tdf#97101:
Starting with version 5.2.0 (2016-06-23) we have a TEXTJOIN() function, and since 5.4 it is well debugged.

Re: A TEXTSPLIT function

Posted: Sat Jul 27, 2024 11:54 am
by JeJe
The LO TextJoin function looks to be a clone of the VBA function - their inverse TextSplit function is here:

https://support.microsoft.com/en-gb/off ... ecace8a6e7

Re: A TEXTSPLIT function

Posted: Sun Jul 28, 2024 10:25 pm
by Villeroy
All the Python string functions in one extension: viewtopic.php?t=83856