• 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: Paul Skinner <email@hidden>
  • Date: Thu, 9 Jan 2003 15:30:41 -0500

On Thursday, January 9, 2003, at 10:28 AM, Arthur J. Knapp wrote:

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

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)
[snip]

You only used numerals in your example input, but I think the handler
itself makes it clear that you want to process all numeric runs in any
given piece of text, so:

snip
I did. Terribly unfair of me to post such a limited example. I just replied to a post by Gary Lists explaining the problem in full detail and the method that I wound up using.

set newStr to lst as string --> "Hello 1234 World 9876"


{ Arthur Knapp, of <http://www.STELLARViSIONs.com>

however, you've cleverly provided a different viewpoint. Thanks for that. It's clear to me that this demarkation of numerals is the way to go in a general case.
Like always, two heads are better than one. Your unusual tack led me to the following. Note I special-cased number runs that precede a decimal. Those are kinda significant. : )

set inputText to "This is test text 123456.7890,123.4646 575943574376"
LimitNumericRuns(inputText, 3)
-->"This is test text 123456.789,123.464 575"


on LimitNumericRuns(inputText, runLimit)
set rareDelimiter to ASCII character 1
repeat with i from 0 to 9
set AppleScript's text item delimiters to (i as string)
set inputText to text items of inputText
set AppleScript's text item delimiters to (rareDelimiter & i & rareDelimiter)
set inputText to inputText as string
end repeat
set AppleScript's text item delimiters to (rareDelimiter & rareDelimiter)
set inputText to text items of inputText
set AppleScript's text item delimiters to ""
set inputText to inputText as text
set AppleScript's text item delimiters to rareDelimiter
set inputText to text items of inputText
set AppleScript's text item delimiters to ""
repeat with i from 2 to ((length of inputText) - 1) by 2
set thisRun to item i of inputText
if length of thisRun > runLimit and item (i + 1) of inputText is not "." then
set item i of inputText to text 1 thru runLimit of thisRun
end if
end repeat
set inputText to inputText as string
end LimitNumericRuns
_______________________________________________
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.
References: 
 >Re: limiting numeric runs (From: "Arthur J. Knapp" <email@hidden>)

  • Prev by Date: Re: Reading input from a delimited source file
  • Next by Date: Re; Keynote, is it scriptable (XML?) -addendum
  • Previous by thread: Re: limiting numeric runs
  • Next by thread: Re: limiting numeric runs
  • Index(es):
    • Date
    • Thread