Split() order into array

J

Jack Leach

Hi and TIA,

I have a requirement where the Split() function must enter the elements into
an array in the order of the string being split. For example,

Dim sString As String, vArr As Variant
sString = "zero;one;two;three"
vArr = Split(sString, ";")

therefore the following should be true:
vArr(0) = "zero"
vArr(1) = "one"
vArr(2) = "two"
vArr(3) = "three"


In my tests this seems to always work. Can anyone confirm that Split() will
ALWAYS order these correctly, before I go counting on it? VBA Help does not
specify...

thanks,
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
P

Paolo

Hi Jack Leach,
I think that the answer to your question is yes, the function keeps the
order of the string. I used it more than once and I always obtained the
expected order (i.e. the one in the source string).
Actually I can't be 110% sure but I can't imagine why the function would
shuffles the order, it would be illogical...:)

HTH Paolo
 
S

Stuart McCall

Jack Leach said:
Hi and TIA,

I have a requirement where the Split() function must enter the elements
into
an array in the order of the string being split. For example,

Dim sString As String, vArr As Variant
sString = "zero;one;two;three"
vArr = Split(sString, ";")

therefore the following should be true:
vArr(0) = "zero"
vArr(1) = "one"
vArr(2) = "two"
vArr(3) = "three"


In my tests this seems to always work. Can anyone confirm that Split()
will
ALWAYS order these correctly, before I go counting on it? VBA Help does
not
specify...

thanks,
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)

I've never known it to do otherwise, and I'd call myself a 'heavy user'. The
function simply reads the string from L to R.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top