# Array Split numbering question/issue?

Hello Everyone,

I am parsing an OpenGL file and am noticing something peculiar about the Split command. I am taking a string which has a text value (v or vn) and a set of three single values (1.000000 -1.000000 -1.000000).

The first time I split a string into an array I use the MyTempArray(0).Val, MyTempArray(1).Val,MyTempArray(2).Val, which I believe is correct by starting at 0 and ending at 2 for a total of three values.

The second time that I split the string into an array in a different method, I use the MyTempArray(1).Val, MyTempArray(2).Val, MyTempArray(3).Val, which is starting at 1 and ending at 3.

Maybe I am doing something wrong, and should the splitting of a string into an array begin at 0 instead of 1 the second time? Here is my code which shows the issue and performs the same way on Windows 10 and my Mac Mini.

ArrayQuestion.xojo_binary_project

Am I programming something wrong, or is this a feature?

I will check the example that I made when I am back on my development computer later tonight.

Unless you expect leading or trailing spaces, it might be a good idea to Trim() the string before splitting.

MyTempArray =Split(Trim(MyTempString), " ")

[quote=285348:@jean-paul devulder]Hi Eugene, you have a mistake
MyTempString = Replace(s, "v ", “”) // you have a space after the letter v
MyTempString = Replace(s, “vn”, “”) // no space !![/quote]

Hi Jean-Paul,

Thanks for the comment. The space after the letter v is intentional, which is definitely a good thought. Thanks!

[quote=285359:@Tim Hare]Unless you expect leading or trailing spaces, it might be a good idea to Trim() the string before splitting.
MyTempArray =Split(Trim(MyTempString), " ")[/quote]

Yes, this is a great ‘good practice’ programming tip, thanks Tim.

I’ll leave this post until tomorrow morning (Mountain Standard Time) for other comments. So far, it kinda looks like a bug… Maybe I’ll have an answer after a good nights sleep.

[quote=285359:@Tim Hare]Unless you expect leading or trailing spaces, it might be a good idea to Trim() the string before splitting.
MyTempArray =Split(Trim(MyTempString), " ")[/quote]

Ahh… Tim was right! I placed his suggested code in the wrong area (Note to self: don’t program when tired).

Thanks Tim!!!

I think what Jean-Paul was getting at is that there should have been a space following vn:

``MyTempString = Replace(s, "vn ", "")``

would also have resolved your issue.

[quote=285389:@Tim Hare]I think what Jean-Paul was getting at is that there should have been a space following vn:

MyTempString = Replace(s, "vn ", “”)
would also have resolved your issue.[/quote]
Yes, your right. Thank you to both Tim and Jean-Paul for their help.