Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!midway!quads.uchicago.edu!goer From: goer@quads.uchicago.edu (Richard L. Goerwitz) Newsgroups: comp.lang.icon Subject: Re: a small problem Message-ID: <1991Jan10.055744.15170@midway.uchicago.edu> Date: 10 Jan 91 05:57:44 GMT References: <9101100454.AA01800@internal.apple.com> Sender: news@midway.uchicago.edu (News Administrator) Distribution: inet Organization: University of Chicago Lines: 28 In <9101100454.AA01800@internal.apple.com> nevin@APPLE.COM (Nevin Liber) writes: > >> ...what I >> want to do is know the total number of characters in s which are >> used for these substrings, however many times they may occur. > >The following will do the job: > > iCharacterCount := 0 > every find(sSubString := !SSubStrings, sLine) do > iCharacterCount +:= *sSubString This is nice. One thing, though, might be added: If any of the strings in set SSubStrings overlap, then the above solution won't work the way Norman wants it to. The substrings variable needs to be a list, with the elements prioritized in some way (e.g. longest strings first): count := 0 s ? while tab(find(tmp := !substrings)) do count +:= *=tmp I haven't tested this code fragment. Oh no! :-) Question: What is the best way to take a list of strings, remove those strings which are substrings of some other string in the list, and then sort by length? -Richard (goer@sophist.uchicago.edu)