Page 1 of 1

number of items?

Posted: Wed Mar 22, 2017 11:01 am
by tusa
Can I count the numbers of items after setting the item delimiter?

Re: number of items?

Posted: Wed Mar 22, 2017 11:22 am
by jmburnod
Hi Tusa,
Yes we can.

Code: Select all

on mouseUp
   put "A_B_C" into tVar
   set the itemdel to "_"
   put the num of items of tVar into tNbItems
   set the itemdel to ","-- dont forget this
   answer "Num of items of tVar =" && tNbItems
end mouseUp
Best regards
Jean-Marc

Re: number of items?

Posted: Wed Mar 22, 2017 12:05 pm
by Klaus
Hi Jean-Marc,

the itemdelimiter is a LOCAL property and will automatically be reset to COMMA
after a handler is finished, so no need for this in your example!


Best

Klaus

Re: number of items?

Posted: Wed Mar 22, 2017 12:15 pm
by Klaus
Hi Tue,
tusa wrote:Can I count the numbers of items after setting the item delimiter?
as Jean-Marc already said, yes, this is surely possible!
You can even swith itemdelimiters to your needs inside of a handler!

To reference your previous (and obviously deleted) posting :D :

Code: Select all

...
put line 2 of the dgtext of grp "my wonderful datagrid" into aVar

## tVar now contains X number of items with TAB delimited
set itemdel to TAB
repeat with i= 1 to the num of items of tVar
   put item i of tVar into tVar2
   set itemdel to ";"
   put "The num of items delimited with ; in item 1 of tVar = " & the num of items of tVar2 & CR after fld "Item info"
   
   ## IMPORTANT or the repeat loop will break:
   set itemdel to TAB
end repeat
...
Hint:
"the num of items" will be 1 even if there is NO itemdelimiter at all in the string to examine!


Best

Klaus

Re: number of items?

Posted: Wed Mar 22, 2017 2:35 pm
by tusa
Thank you, that solved my problem.
I did only use part of your suggestion, but that was what I needed.