Counting Chars by ASCI Values
Jim Ault
JimAultWins at yahoo.com
Wed Mar 1 00:13:36 EST 2006
On 2/28/06 8:01 PM, "Jim Lambert" <jiml at netrin.com> wrote:
> Personally I prefer the itemcount technique.
>
Caution when counting words, items, lines in xtalk.
Using either "the number of lines in"
or "for each" can give unexpected results.
If the last character in a field is a return, the last line is empty and
DOES NOT COUNT. The same for ("," items) and (" " words)
Using "& null" will work for words/items/lines
and give you what you would want in most cases.
See below.
Paste the following into a new mainstack stack script, dblclk and study the
difference.
---start copy --------------------------------------
on mouseDoubleUp
put "one,two,three,four," into txtList --note last comma
replace "," with cr in txtList
-------- usual 2 methods ...oops
repeat with x = 1 to the number of lines in txtList
put "x is " & x into line x of withXresult
end repeat
repeat for each line LNN in txtList
put "money" & cr after forEachResult
end repeat
------- Ahh, more like what we naturally think
repeat with x = 1 to the number of lines in (txtList & null)
put "x is " & x into line x of withXnullResult
end repeat
repeat for each line LNN in (txtList & null)
put "money" & cr after forEachNullResult
end repeat
-------------------
breakpoint
--note the resultant variables in variable watcher
--withXresult = 4 lines
--forEachResult = 4 lines
--withXnullResult = 5 lines
--forEachNullResult = 5 lines & more money
--basically, if the last word/item/line is empty it does not count
--adding null forces it to count
end mouseDoubleUp
---end copy -------------------------------
Jim Ault
Las Vegas
More information about the use-livecode
mailing list