The Split command

This forum is meant for requesting technical support or reporting bugs.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

The Split command

Postby reneuend » Wed Dec 11, 2013 1:32 am

I've been using the Split command to push delimited strings in to arrays to make it easier to perform logic tasks.

Code: Select all
test = "This,is,a,comma,delimited,string"
myArray = Split(test,",")
msgbox UBound(myArray)   'This returns 5 instead of the expected 6

You would think that the array would contain 6 elements, but for some reason is doesn't get the last element.
The fix is to attach a comma to the end of the string. You can do this without adding the comma to the variable, test, by concatenating the comma as a literal in the Split command like this:

Code: Select all
myArray = Split(test & ",", ",")
msgbox UBound(myArray)  'Now all 6 elements are added to the array

Here is a test I ran to prove it:

Code: Select all
sTest = "1,2,3,4,5,6"
myArray = Split(sTest,",")
Text(4).caption = UBound(myArray)
myArray2 = Split(sTest & ",",",")
Text(5).caption = UBound(myArray2)


User avatar
Posts: 2743
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 4 guests