From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: buffer1.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Simon Clubley Newsgroups: comp.lang.ada Subject: Re: How to check if letters are in a string? Date: Sat, 18 Jul 2015 11:07:05 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <53a16384-fa63-479c-9421-553683dd6009@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Date: Sat, 18 Jul 2015 11:07:05 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="809c353be8a1b93f2b55d96dd7c03845"; logging-data="30279"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dgwhAkxEFofuaxaSnmr0poZ5MpmXdTsQ=" User-Agent: slrn/0.9.9p1 (Linux) Cancel-Lock: sha1:GtjUfmP88alsQUBc9dSGTwPk5Ek= Xref: number.nntp.giganews.com comp.lang.ada:194178 Date: 2015-07-18T11:07:05+00:00 List-Id: On 2015-07-18, Nasser M. Abbasi wrote: > On 7/18/2015 4:00 AM, Trish Cayetano wrote: >> Hi, >> >> How do you check if (exact number of) letters are in a string? >> >> 1. This example should PASS because every letter is found in the string >> LETTERS: HID >> STRING: HIDDEN >> > > I do not follow. The 'D' in 'letters' occur 1 time but it occurs > 2 times in 'string'. So this is not the _exact number_ of > letters in the string. > >> 2. This example should FAIL because the letters contain 2 N's but the string only has 1 N. >> LETTERS: NINE >> STRING: HIDDEN >> > > So why now this fails when 'letters' has more N's than in string, but > the first case did not fail when 'letters' had less D's than in string? > > I think your problem specifications is not clear. > I think the characters in "letters" are supposed to be a subset of the characters in "string", To the OP: a couple of ways immediately come to mind. 1) Maintain a seperate boolean array whose size is the size of "string". Set the position to true when a letter matches and ignore that position when checking for subsequent letters. or 2) Assign "string" to a temporary string and remove the matching character from each pass. You use that temporary string when searching for subsequent letters. I really hope I have not just done your homework for you. :-) Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world