Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
USA
Asked — Edited
Resolved Resolved by DJ Sures!

Split Does Not Work

This code works as expected:

Code:


1: ClearVariables()
2: $Statement = "one,two,three"
3: $token1 = Split($Statement, ",", 0)
4: $token2 = Split($Statement, ",", 1)
5: $token3 = Split($Statement, ",", 2)



The code below does not work:

Code:


1: ClearVariables()
2: $Statement = "one two three"
3: $token1 = Split($Statement, " ", 0)
4: $token2 = Split($Statement, " ", 1)
5: $token3 = Split($Statement, " ", 2)


Line 3 is executed but does not get the token "one" and line 4 generated the error:

Quote:


Error on line 4: Error splitting 'one two three' with SplitChar: '' to field #1. Index was outside the bounds of the array.


ARC Pro

Upgrade to ARC Pro

Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.

AI Support Bot
Related Content
Synthiam
South Africa
#2  
I don't know much about coding but could t have something to do with the comma because the first code has a comma in between one and two and two and three where as the second code does not have a comma on line 2
#3  
@Mohamed.r

Yes and no. Yes in that you are correct that there is a comma in one example and a space in the next example and that is why it is not working. But no, because it should still work with a space between the words instead of a comma. As long as you use a space character in the Split() function instead of the comma it should work the same. So, DJ is checking out why the space character separator is not working.
PRO
Synthiam
#4  
fixed in next release

(i'm having a productive flight home)
PRO
USA
#5  
Thanks
PRO
Synthiam
#6  
Plane just landed - so I'll have the new release up when I get home.