• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: limiting numeric runs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: limiting numeric runs


  • Subject: Re: limiting numeric runs
  • From: Gary Lists <email@hidden>
  • Date: Wed, 08 Jan 2003 19:36:11 -0500

On or about 1/8/03 12:47 PM, Paul Skinner wrote:

> LimitNumericRuns("676798697675785", 4)
> -->"6767"
>
> on LimitNumericRuns(inputText, runLengthLimit)
> set inputText to characters of inputText
> set numeralRun to 0
> repeat with i from 1 to length of inputText
> set thisw to item i of inputText
> if thisw is in {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"} then
> set numeralRun to numeralRun + 1
> if numeralRun > runLengthLimit then set item i of inputText to ""
> else
> set numeralRun to 0
> end if
> end repeat
> set AppleScript's text item delimiters to ""
> return inputText as string
> end LimitNumericRuns

Paul,

From what you wrote, given the example you used, if that is all you want,
why not just return characters 1 thru runLengthLimit of inputText?

But, since that seems so very obvious, I presumed that a sample input might
also be: "abc1def2ghi3jkl4mno5pqr6stu7vwx8yz"

where you didn't just want the first X characters of a numeric string.
(Right?) but X number of numeric characters from a larger chunk of mixed
stuff...

So...

Your script chrono-timed with "0.033333335072"

The one below brought that time to "0.016666667536"

Here is what I came up with...not that much different than yours really,
since the "logic" of the problem is pretty much the same. Except in your
sample, you continued to loop through things even if the slots were filled,
whereas I just bail out once the slots are taken. I don't know if the
repeated matching against a "literal list" inside the loop in your sample is
slower or faster than setting the list to a property var and then comparing,
but I did it with a property anyway. (Referring to the 'is in' line in both
our efforts.)

-- ====================
property numDigits : {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}

xNumCharsFromManyChars("abc1def2ghi3jkl4mno5pqr6stu7vwx8yz", 6)
--> "123456"
--> chrono = 0.016666667536

on xNumCharsFromManyChars(manyChars, numMax)
set cntr to 0
set digChars to ""
repeat with i from 1 to number of characters of manyChars
set tempC to character i of manyChars
if (tempC is in numDigits) then
set cntr to cntr + 1 -- got a keeper
set digChars to digChars & tempC
end if
if cntr = numMax then exit repeat
end repeat
return digChars
end xNumCharsFromManyChars
-- ====================


HTH
--
Gary

Incoming replies are auto-deleted.
Please post directly to the list or newsgroup.

Really need direct? Rot me at:
email@hidden
Lbhe fhowrpg zhfg ortva "abgwhax:" (ab dhbgrf)
Avpr gb zrrg lbh! Qba'g fcnz zr.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: limiting numeric runs
      • From: Paul Skinner <email@hidden>
References: 
 >limiting numeric runs (From: Paul Skinner <email@hidden>)

  • Prev by Date: Re: Safari again
  • Next by Date: Re: OSX script to change/copy file icon ?
  • Previous by thread: limiting numeric runs
  • Next by thread: Re: limiting numeric runs
  • Index(es):
    • Date
    • Thread