Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.
Get Started

Asked
Resolved Resolved by ptp!

Can Someone Spot The Error In My Code?

Can someone tell me why I am getting this error?
I must be going code blind or I found a bug.
ARC version 2020.05.18.00

Error on line 4: Missing ) in Expression


Code:


$HumanSaid = "birds can fly"
$Sentence = $HumanSaid
$xCount = 0
repeatwhile(contains($Sentence, " "))
$xStrLength = Length($Sentence)
$xIndex1 = IndexOf($Sentence, " ")
$Sentence = SubString($Sentence,$xIndex1 + 1,($xStrLength - ($xIndex1 + 1)))
$xCount = $xCount + 1
endrepeatwhile
$xCount = $xCount + 1

$WordCount = $xCount


Related Hardware EZ-Robot EZ-B v4
Related Control Script
#1   — Edited
ASFAIK there is no error, it's an EZ-Script bug this code works:

Code:

$HumanSaid = "The quick brown fox, jumps over the @## lazy dog !!!"
$Sentence = $HumanSaid
$xCount = 0

$contains=contains($Sentence, " ")
repeatwhile($contains)
$xStrLength = Length($Sentence)
$xIndex1 = IndexOf($Sentence, " ")
$Sentence = SubString($Sentence,$xIndex1 + 1,($xStrLength - ($xIndex1 + 1)))
$xCount = $xCount + 1
$contains=contains($Sentence, " ")
endrepeatwhile
$xCount = $xCount + 1
$WordCount = $xCount
print("Total words: " + $wordCount)

Quote:

Start
> Total Words: 11
Done (00:00:00.0219259)

You should move away from EZ-Script to Javascript or Python.

Javascript version:

Code:

function countWords(str) {
var matches = str.match(/[\w\d\’\'-]+/gi);
return matches ? matches.length : 0;
}

text = "The quick brown fox, jumps over the @## lazy dog !!!"
print("Total words: " + countWords(text) );

Quote:

Start
> Total words: 9
Done (00:00:00.0128812)

Python version:

Code:

import string 

text = "The quick brown fox, jumps over the @## lazy dog !!!"
words = sum([i.strip(string.punctuation).isalpha() for i in text.split()])
print ("Total words: " + str(words))

Quote:

Start
> Total words : 9
Done (00:00:00.0184166)
.
#2  
Thank you PTP, I am starting to use JavaScript. But when I can't find what I want to do it is so easy to fall back to EZ-Script.
Have to start from scratch as most of my scripts just vanished when I installed ARC and I can't find any backups and I know I have made lots.

by the way what does ASFAIK mean?
#3  
AFAIK  =As Far As I Know

ASFAIK = PTP's version of AFAIK (All rights reserved):)
Synthiam
#5  
Are you just trying to count the number of words? Use the split() function and get the array length
#6  
@ DJ, Yup that is what I am doing.
Thank you DJ