Re: Strip characters without recursive loop
Re: Strip characters without recursive loop
- Subject: Re: Strip characters without recursive loop
- From: Emmanuel <email@hidden>
- Date: Wed, 20 Aug 2003 15:07:09 +0200
At 10:07 AM +0200 20/08/03, julifos wrote:
>
Thought this would also fall into the topic's scope, though this probably
>
isn't as fastest as plain vanilla:
>
>
#####################################
>
set x to "sdfk47fd-73fl"
>
{x, extractNums(x), delNums(x)}
>
--> {"sdfk47fd-73fl", "4773", "sdfkfd-fl"}
>
>
to extractNums(x)
>
do shell script "printf " & quoted form of x & " | tr -cd '[0-9]'"
>
end extractNums
>
to delNums(x)
>
do shell script "printf " & quoted form of x & " | tr -d '[0-9]'"
>
end delNums
>
#####################################
This is a cool vanilla solution, only if users are aware of the limitations.
I have just tested "extractNums" on a string of 31,000 characters exactly. It does not return an error, only the empty string (actually there are 544 figures). (On a still longer string I get an error). Wicked behavior, no?
My advice is like JB:
--------------- uses Satimage.osax
change "[^0-9]|\\r" into "" in x with regexp
---------------
This will support strings of virtually any length.
Emmanuel
_______________________________________________
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.