AW: AW: Lines, items, repeat loops, > not always what you think

Ken Ray kray at sonsothunder.com
Thu Oct 20 18:16:41 EDT 2005


On 10/20/05 5:06 PM, "Ken Ray" <kray at sonsothunder.com> wrote:

>> function delimCount strr, del
>>     put the itemDelimiter into saveDelim
>>     set the itemDelimiter to del
>>     get the number of items in strr
>>     if the last char of strr is del then add 1 to it
>>     set the itemDelimiter to saveDelim
>>     return it
>> end delimCount
> 
> This one is slightly faster, but is less lines:
> 
> function delimCount tStr,tDel
>   replace tDel with CR in tStr
>   return the number of lines of (tStr & null)
> end delimCount
> 
> Also note that a modified form of this can be used to count any number of
> characters in a string:
> 
> function charCount tStr,tChar
>   if tChar <> CR then replace CR with "" in tStr
>   replace tChar with CR in tStr
>   return the number of lines of (tStr & null)
> end charCount

Whoops! My bad... it should be this:

function delimCount tStr,tDel
  replace tDel with CR in tStr
  return (the number of lines of (tStr & null))-1
end delimCount

and

function charCount tStr,tChar
  if tChar <> CR then replace CR with "" in tStr
  replace tChar with CR in tStr
  return (the number of lines of (tStr&null))-1
end charCount

Sorry!

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list