Insert and delete Commas
Ken Ray
kray at sonsothunder.com
Thu Sep 19 00:51:01 EDT 2002
Thanks, Jan... It took a while before I got the automated response of "see
string parsing... think RegEx". One of these days, I was hoping that MC/Rev
could do away with the need to declare the local variables before you used
matchText/matchChunk and create them automatically for you... that would
remove yet another line and also some troubleshooting for people who forget
to declare them.
Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
----- Original Message -----
From: "Jan Schenkel" <janschenkel at yahoo.com>
To: <use-revolution at lists.runrev.com>
Sent: Wednesday, September 18, 2002 4:56 PM
Subject: Re: Insert and delete Commas
> Hi Ken,
>
> Congratulations on yet another excellent regular
> expression solution. It's just not an automated
> response in my brain set ;-)
> And what-do-you-know : Ken's version even fits in the
> Starter Kit 10-lines limit. Now where did I put that
> perl-book again...
>
> *drowsy smile*
>
> Jan Schenkel.
>
> "As we grow older, we grow both wiser and more foolish
> at the same time." (De Rochefoucald)
>
> --- Ken Ray <kray at sonsothunder.com> wrote:
> > Or, using Regular Expressions (my fave):
> >
> > function insertCommas pNumber
> > local tMinusHold,tMainNum,tDecimalHold
> > get
> >
>
matchText(pNumber,"([-]?)([0-9]*)[\.]?([0-9]*)",tMinusHold,tMainNum,tDecimal
> > Hold)
> > if it is true then -- should be, but can't hurt
> > to check
> > put "" into returnVal
> > if tDecimalHold <> "" then put "." before
> > tDecimalHold
> > repeat with x = length(tMainNum) down to 1
> > if ((length(tMainNum) - x) mod 3 = 0)
> > and (x <>
> > length(tMainNum)) then \
> > put "," before returnVal
> > put char x of tMainNum before returnVal
> > end repeat
> > return tMinusHold & tMainNum & tDecimalHold
> > end if
> > end insertCommas
> >
> > And to explain the regEx (which is something I do
> > every time I make a regex
> > post), here's how it breaks up:
> >
> > ([-]?)
> > Look for 0 or 1 occurrence ("?") of a hyphen
> > ("[-]"), and return it
> > ("()") into the first variable provided
> > (tMinusHold).
> >
> > ([0-9]*)
> > Then look for 0 or more occurrences ("*") of a
> > number ("[0-9]"), and
> > return it ("()") into the second variable provided
> > (tMainNum).
> >
> > [\.]?
> > Then look for 0 or 1 occurence ("?") of a
> > decimal point ("\." - the "\"
> > escapes this 'special' character so it's not
> > misinterpreted). Since there's
> > no parentheses, don't return anything, just use it
> > as a delimiter.
> >
> > ([0-9]*)
> > Finally, look for 0 or more occurrences ("*") of
> > a number ("[0-9]"), and
> > return it ("()") into the last variable provided
> > (tDecimalHold).
> >
> > Hope this helps,
> >
> > Ken Ray
> > Sons of Thunder Software
> > Email: kray at sonsothunder.com
> > Web Site: http://www.sonsothunder.com/
> >
> > [snip]
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! News - Today's headlines
> http://news.yahoo.com
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
More information about the use-livecode
mailing list