Page 1 of 1
[Solved] Split a string into an array for each character
Posted: Sun Oct 06, 2024 11:06 am
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
Re: Split a string into an array for each character
Posted: Sun Oct 06, 2024 1:42 pm
by Mr.Dandy
Well, Mid do the job
But I don't know why Split instruction not?

Re: Split a string into an array for each character
Posted: Sun Oct 06, 2024 4:16 pm
by karolus
Re: Split a string into an array for each character
Posted: Sun Oct 06, 2024 4:52 pm
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.
Re: Split a string into an array for each character
Posted: Sun Oct 06, 2024 5:57 pm
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.
Re: Split a string into an array for each character
Posted: Sun Oct 06, 2024 8:06 pm
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)
Re: Split a string into an array for each character
Posted: Mon Oct 07, 2024 5:11 pm
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))