• 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: julifos <email@hidden>
  • Date: Thu, 09 Jan 2003 10:11:42 +0100

> 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

I don't know if you're looking for this, but take a look:

LimitNumericRuns2("676798697675785", 4)

on LimitNumericRuns2(inputText, runLengthLimit)
set inputText to text from character 1 of inputText to character
runLengthLimit of inputText
--> apply limit
try
return (inputText as number) as string
--> if you can coerce it to number, return result (as string?)
end try
end LimitNumericRuns2

But if you wish reset the counter where you find a character other than a
number (that's: if you must handle not-numeric characters):
Eg.-> if ("4z17", 2), return "17"
Then you need the repeat loop.

Anyway, you could include this routine in your LimitNumericRuns and it could
increase your speed when you receive a string-of-numbers:

on LimitNumericRuns(inputText, runLengthLimit)
try
return ((characters 1 thru runLengthLimit of inputText as string) as
number) as string
on error
--> go to the repeat loop
end try
end LimitNumericRuns

JJ
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
_______________________________________________
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.

  • Prev by Date: Re: Keynote, is it scriptable?
  • Next by Date: Re: applescript-users digest, Vol 3 #1219 - 15 msgs
  • Previous by thread: Re: limiting numeric runs
  • Next by thread: Re: limiting numeric runs
  • Index(es):
    • Date
    • Thread