A TEXTSPLIT function

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
User avatar
Lupp
Volunteer
Posts: 3693
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

A TEXTSPLIT function

Post 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 164 times
Last edited by Lupp on Sat Jul 27, 2024 10:49 am, edited 1 time in total.
On Windows 10: LibreOffice 25.2.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
cwolan
Posts: 165
Joined: Sun Feb 07, 2021 3:44 pm

Re: A TEXTSPLIT function

Post 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.
OpenOffice 1.1.5 – 4.1.15
LibreOffice 3.3.0.4 – 25.2
Windows 7,10,11 64-bit
JeJe
Volunteer
Posts: 3064
Joined: Wed Mar 09, 2016 2:40 pm

Re: A TEXTSPLIT function

Post 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
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Villeroy
Volunteer
Posts: 31344
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: A TEXTSPLIT function

Post by Villeroy »

All the Python string functions in one extension: viewtopic.php?t=83856
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply