[Solved] Split a string into an array for each character

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
User avatar
Mr.Dandy
Posts: 461
Joined: Tue Dec 11, 2012 4:22 pm

[Solved] Split a string into an array for each character

Post by Mr.Dandy »

Hello all,

This code don't work:

Code: Select all

Sub Main
	myWord = "FOOBAR"
	aWord = Split(myWord,"",Len(MyWord)-1)
	msgbox aWord(0)
End Sub
This returns entire string and not only "F"
if anyone can take a look
Last edited by Mr.Dandy on Wed Oct 09, 2024 10:38 am, edited 1 time in total.
OpenOffice 4.1.12 - Windows 10
User avatar
Mr.Dandy
Posts: 461
Joined: Tue Dec 11, 2012 4:22 pm

Re: Split a string into an array for each character

Post by Mr.Dandy »

Well, Mid do the job

But I don't know why Split instruction not? :knock:
OpenOffice 4.1.12 - Windows 10
User avatar
karolus
Volunteer
Posts: 1227
Joined: Sat Jul 02, 2011 9:47 am

Re: Split a string into an array for each character

Post by karolus »

```
YOURword = "FOOBAR"
print( YOURword[0] )
```
search.php?st=0&sk=t&sd=d&sr=posts&author_id=59382
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
Zizi64
Volunteer
Posts: 11486
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Split a string into an array for each character

Post by Zizi64 »

But I don't know why Split instruction not?

Code: Select all

aWord = Split(myWord,"",Len(MyWord)-1)
I suppose that:
The separator character must be a real (non-empty) string.
Because there is not any separator character, therefore the word will not be splitted.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
floris v
Volunteer
Posts: 4573
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Split a string into an array for each character

Post by floris v »

Code: Select all

aWord = Split(myWord,"",Len(MyWord)-1)
aWord needs to be an array, and it probably also needs to be dim'd. The default delimiter is " ", a space. See https://help.libreoffice.org/6.2/en-US/ ... 20314.html - Google couldn't find that page for OpenOffice.
LibreOffice 24.2.7.2 on Ubuntu Linux
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
cwolan
Posts: 182
Joined: Sun Feb 07, 2021 3:44 pm

Re: Split a string into an array for each character

Post by cwolan »

OpenOffice Help, the Split function:
Syntax:
Split (Text As String, delimiter, number)
[...]
delimiter (optional): A string of one or more characters length that is used to delimit the Text. The default is the space character.
The length of an empty string is 0.

Source code (AOO): RTLFUNC(Split)
OpenOffice 1.1.5 – 4.1.15
LibreOffice 3.3.0.4 – 25.2
Windows 7,10,11 64-bit
JeJe
Volunteer
Posts: 3076
Joined: Wed Mar 09, 2016 2:40 pm

Re: Split a string into an array for each character

Post by JeJe »

You can convert to a byte array by assignment

Code: Select all

dim b() as byte
myWord = "FOOBAR"
b= myWord
msgbox chr(b(0))
msgbox chr(b(2))


Edit:

Or

Code: Select all

dim b() as byte
myWord = "FOOBAR"
b= strconv( myWord,128) 'from unicode
msgbox chr(b(0))
msgbox chr(b(1))
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Locked