Re: Strip characters without recursive loop
Re: Strip characters without recursive loop
- Subject: Re: Strip characters without recursive loop
- From: julifos <email@hidden>
- Date: Tue, 19 Aug 2003 11:34:42 +0200
>
Hi List
>
>
Is it possible to string all non numerical characters from a string, without
>
looping through each character?
>
I realise that this is probably not possible.... but it would make my script
>
run a lot quicker.
>
>
Example:
>
>
set theString to "1234-56abc"
>
set theResult to characters of the string whose kind is integer
>
>
Just hoping to save a bit of time.
>
>
Thanks in advance
>
>
D
You can save lots of time looping through 10 numbers instead a 20000 bytes
string, but won't save nothing in these samples, with a 15-byte string:
--> to extract numbers:
###################
set Nums to "0123456789"
set theString to "alsdjaf465gf789"
set numsWithin to {}
repeat with i in Nums
if (offset of i in theString) 0 then set numsWithin's end to i's
contents
end repeat
numsWithin --> {"4", "5", "6", "7", "8", "9"}
###################
--> to extract non-numbers:
###################
set Nums to "0123456789"
set theString to "alsdjaf465gf789"
tell (a reference to AppleScript's text item delimiters)
repeat with i in Nums
set contents to i
set theString to theString's text items
set contents to ""
set theString to "" & theString
end repeat
set contents to {""}
end tell
theString --> "alsdjafgf"
###################
jj
_______________________________________________
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.