Counting Chars by ASCI Values

Jim Ault JimAultWins at
Wed Mar 1 10:25:57 EST 2006

On 3/1/06 5:08 AM, "Cubist at" <Cubist at> wrote:

> In a message dated 2/28/06 6:20:02 PM, Todd Geist
> <tg.lists at> writes:
>> I need to count the number of times a Character occurs in text
>> string. The character will be high or Low ASCII.  SO I need to input
>> the value as an ASCII value.
>> Anybody have any scripts that can get me started?
>    The replies you've gotten thus far have used loops to explicitly count the
> occurences of whatever-character-it-is. Here's a different way to do it,
> using the "replace" function, which could be faster:

Actually, my original post used the following technique:

set the itemDel to "¼"
get the number of items in (textStr & null)

which does not require a repeat loop or replace or a function or
establishing more variables.

One post was done to show the precaution of counting any container for
words, items, lines where the last to be counted was empty.

The best implementation would be either:
-- method 1 inline
put the itemDel into prevDel
set the itemDel to asciiChar
get the number of items in (textStr & null)
set the itemDel to prevDel

---method 2 function
function getCharCount asciiChar
   set the itemDel to asciiChar
   return  the number of items in (textStr & null)
end getCharCount 

--and now the itemDel does not have to reset
put getCharCount("¼") into howMany

So many ways, so many choices :-)

Jim Ault
Las Vegas

More information about the Use-livecode mailing list