• 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: How best to extract digits from a string?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How best to extract digits from a string?


  • Subject: Re: How best to extract digits from a string?
  • From: Paul Skinner <email@hidden>
  • Date: Fri, 27 Apr 2001 22:35:40 -0400

on 4/27/01 6:30 PM, Bill Cheeseman wrote:

SNIP
> I even tried a couple of tricks based on foreknowledge that the output
> string for an area code and telephone number has to be 10 characters long,
> but I couldn't find anything faster.
>
> --
>
> Bill Cheeseman - email@hidden
> Quechee Software, Quechee, Vermont, USA

Faster,faster, everybody wants faster. What about linear?
Here's one that's 60 times slower ( .25 seconds on my PB 400 ) but, It will
never get much slower than that. : )
Arthur J. Knapp proposed a solution that used TIDs for a possible
speedup on larger strings, but it still iterated based on the length of the
string. I also got stack overflow errors using his script with 20000
character strings.
Instead of tweeking the 'add it if it's a number' route I remove
everything thats not a number. 256 iterations. pass it 20000 characters and
it still only has to do 255 iterations. At 20000 characters it takes .5
seconds vs 157 seconds or so for Paul Berkowitz's original method or the
similar variants (these scripts times are very non-linear when fed more than
several hundred characters ).
Kind of like asking; which is faster the dragster or the sports car?
It depends on where you drive them.

--begin script
repeat with asciiCode from 0 to 255
if asciiCode < 47 or asciiCode > 58 then
set AppleScript's text item delimiters to ASCII character asciiCode
set theText to every text item of theText
set AppleScript's text item delimiters to ""
set theText to theText as text
end if
end repeat
--end script

--
Paul Skinner


  • Follow-Ups:
    • Re: How best to extract digits from a string?
      • From: Bill Cheeseman <email@hidden>
References: 
 >Re: How best to extract digits from a string? (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: SDebugger: info on keyboard shortcuts 4 attached scripts
  • Next by Date: Re: Mike Mortin is out of the office.
  • Previous by thread: Re: How best to extract digits from a string?
  • Next by thread: Re: How best to extract digits from a string?
  • Index(es):
    • Date
    • Thread