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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8f802583e5c84fa X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!bandi.nntp.kabelfoon.nl!news.banetele.no!news.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: String filtering Date: Tue, 27 Sep 2005 09:38:40 +0200 Organization: Jacob's private Usenet server Message-ID: References: NNTP-Posting-Host: hugin.crs4.it Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: jacob-sparre.dk 1127806720 30791 156.148.71.67 (27 Sep 2005 07:38:40 GMT) X-Complaints-To: sparre@jacob-sparre.dk NNTP-Posting-Date: Tue, 27 Sep 2005 07:38:40 +0000 (UTC) User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:iWVwI8RlygmajCSSkflRPviJUoE= Xref: g2news1.google.com comp.lang.ada:5176 Date: 2005-09-27T09:38:40+02:00 List-Id: David Trudgett wrote: > I've been puzzling for a little bit over a good way to filter out > unwanted characters from a string. In particular, I have an > unbounded string and want to filter out of it all characters not in > 'a'..'z', 'A'..'Z', '0'..'9'. So far I've only thought of tedious > ways to do it. Is there an easy way to do it using the string > handling facilities in Ada? I think I almost got there with the idea > of using Maps.Character_Set, and so on, but I haven't quite pieced > it together yet. I would probably simply iterate over the elements in the string and copy those which a call to "function Is_In (Element : in Character; Set : in Character_Set) return Boolean;" indicate to the target string. You could use "function Count (Source : in Unbounded_String; Set : in Maps.Character_Set) return Natural;" to preallocate the target string, if you're afraid appending to an unbounded string is too slow for your purpose. Greetings, Jacob -- Atheism is a non-prophet organisation.