problem with counting words
Peter M. Brigham
pmbrig at gmail.com
Wed Oct 15 22:18:47 EDT 2014
On Oct 14, 2014, at 3:45 PM, Richard Gaskin wrote:
> function nDepth
> get param(1)
> repeat with i = 2 to paramCount() step 2
> set the itemDel to param(i+1)
> get item param(i) of it
> end repeat
> return it
> end nDepth
Another one to add to my collection. Thanks, Richard!
If you don't have to deal with nested itemdelims, here's a function to use for the simple case:
function getItem tList,tIndex,tDelim
-- returns item # tIndex of tList, given itemdelimiter = tDelim
-- could just "get item tIndex of tList" in the calling handler but
-- then have to set and restore the itemDelimiter, so this is less hassle
-- defaults to tDelim = comma
if tDelim = empty then put comma into tDelim
set the itemdelimiter to tDelim
return item tIndex of tList
end getItem
So,
put getItem(tList,3,"/") into tName
is simpler than
put the itemDel into oldDelim
set the itemDel to "/"
put item 3 of tList into tName
set the itemDel to oldDelim
and you don't risk forgetting to reset the itemDelim, which I often forget to do, especially in repeat loops….
-- Peter
Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig
More information about the use-livecode
mailing list