• 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: similar strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: similar strings


  • Subject: Re: similar strings
  • From: deivy petrescu <email@hidden>
  • Date: Mon, 9 Jan 2006 16:21:40 -0500


On Jan 9, 2006, at 11:39, Feat wrote:

At 15:50 +0000 2006/01/09, Barry Wainwright wrote:
Not sure what you are asking for here - do you want to sort the strings by the 'abc' field, or ignoring the 'abc' field?

No, thank you: I need find the longest substring shared by two strings, given that the substring is -- unfortunately -- not known in advance.


I want to group files according to similarity in their names: the substring is not known in advance, it has to be computed for each pair of files... For instance:

	"abcd" and "zaxbcybcdw" share "a", "bc", and "bcd"

the latter being the longest -- and, incidentally, the last to be found...

My goal is to fan out a few thousand files into folders, so the number of files per folder will be under 512 -- I have the feeling Finder tends to react very slowly when it has to deal with folders bigger than 500 items.

I'm not sure about the exact number, but I guess it changes behaviors around this threshold.

--
Jym Feat -- Paris FR 75018

Jym:

This script will find the longest matched substring of a string
Polish it. I did not lok for the short string as this should be easy:

<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)
repeat with l from (k + 1) to (count of shortString)
set {tf, tb, tm} to {text l thru -k of shortString, text k thru -l of shortString, text (k + 1) thru -(k + 1) 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}
if tm is in longString then if length of tm > item 2 of found then set found to {tm, length of tm}
end repeat
end repeat
else
return shortString
end if
found


  --  {"now is the time for a", 21}
</script>

See, AppleScript can do amazing things!

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


  • Follow-Ups:
    • Re: similar strings
      • From: Feat <email@hidden>
References: 
 >Re: similar strings (From: Barry Wainwright <email@hidden>)
 >Re: similar strings (From: Feat <email@hidden>)

  • Prev by Date: Re: text Encoding with Write to file
  • Next by Date: Re: similar strings
  • Previous by thread: Re: similar strings
  • Next by thread: Re: similar strings
  • Index(es):
    • Date
    • Thread