• 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
limiting numeric runs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

limiting numeric runs


  • Subject: limiting numeric runs
  • From: Paul Skinner <email@hidden>
  • Date: Wed, 8 Jan 2003 12:47:54 -0500

I need to limit the length of numeric runs in a given text. Does anyone have a suggestion as to a non-looping solution?
This is too slow.

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 Skinner
_______________________________________________
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: Emmanuel <email@hidden>
    • Re: limiting numeric runs
      • From: Gary Lists <email@hidden>
  • Prev by Date: Getting screen resolution the Safari way
  • Next by Date: Re; Keynote, is it scriptable (XML?)
  • Previous by thread: Re: Test for BSD subsystem
  • Next by thread: Re: limiting numeric runs
  • Index(es):
    • Date
    • Thread