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


$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-B v4
Related Control Script

ARC Pro

Upgrade to ARC Pro

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

PRO
USA
#1   — Edited

ASFAIK there is no error, it's an EZ-Script bug this code works:

$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:

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:

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)

.

PRO
USA
#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?

PRO
USA
#3  

AFAIK  =As Far As I Know

ASFAIK = PTP's version of AFAIK (All rights reserved):)

PRO
Synthiam
#5  

Are you just trying to count the number of words? Use the split() function and get the array length

PRO
USA
#6  

@ DJ, Yup that is what I am doing. Thank you DJ