Re: similar strings
Re: similar strings
- Subject: Re: similar strings
- From: deivy petrescu <email@hidden>
- Date: Mon, 9 Jan 2006 21:38:46 -0500
On Jan 9, 2006, at 16:26, deivy petrescu wrote:
Correct my script to:
Ok, final version:
<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)
set tm to text (k + 1) thru -(k + 1) of shortString
if tm is in longString then if length of tm > item 1 of found then
set found to {length of tm, tm}
set max to cst - 2 * k + 1
repeat with l from (k + 1) to (cst - k)
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 1 of found then
set found to {length of tf, tf}
if tb is in longString then if length of tb > item 1 of found then
set found to {length of tb, tb}
if item 1 of found ≥ max then return item 2 of found
end repeat
end repeat
else
return shortString
end if
</script>
It cuts the time for a longer string to about half!
Some comments:
The script has some problems, namely, it does not handle the case of
two different strings of the same length as being maximal. The script
handles this by using using a hierarchy, if you find two different
strings of the same length then the one from left to right has
priority over the right to left. If you want to change the order then
change the if lines with tf (text forward) and tb (backwards).
Deivy
_______________________________________________
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