Re: similar strings
Re: similar strings
- Subject: Re: similar strings
- From: Adam Bell <email@hidden>
- Date: Mon, 9 Jan 2006 18:00:20 -0400
Extremely clever, Deivy, and surprisingly fast. I've got a folder of my scripts saved as text that I normally search with BBEdit. Now I can search for a piece of a phrase in AppleScript.
On 1/9/06, deivy petrescu <email@hidden> wrote:
Correct my script to:
<script>
set shortString to "The answer on is now is the time for a party
with foxes and cows but no good men"
set longString to "Now is the time for all good men to come to the
aid of the party while the quick brown fox jumps over the lazy dog.
How now brown cow"
set cst to (count of shortString)
set found to {"", 0}
if shortString is not in longString then
repeat with k from 1 to (cst div 2 + 1)
set tm to text (k + 1) thru -(k + 1) of shortString
if tm is in longString then if length of tm > item 2 of found then
set found to {tm, length of tm}
repeat with l from (k + 1) to (count of shortString)
set {tf, tb} to {text l thru -k of shortString, text k thru -l of
shortString}
if tf is in longString then if length of tf > item 2 of found then
set found to {tf, length of tf}
if tb is in longString then if length of tb > item 2 of found then
set found to {tb, length of tb}
end repeat
end repeat
else
return shortString
end if
found
</script>
You do not have to put the "set tm to text (k + 1) thru -(k + 1) of
shortString" inside the inner loop.
It makes the search much faster, obviously!
Deivy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden
This email sent to email@hidden
--
Some minds remain open long enough for a truth to both enter and leave without processing.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden