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,FREEMAIL_FROM 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!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 27 Sep 2005 20:54:09 -0500 From: "Steve" Newsgroups: comp.lang.ada References: Subject: Re: String filtering Date: Tue, 27 Sep 2005 18:54:54 -0700 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: NNTP-Posting-Host: 24.22.63.157 X-Trace: sv3-eCDfjfuXOZkB4DfGR5Yos+7gBtJNwXl5YPgMaGc/A1Aw36Bx0/4QDDLEQyuqCJl8E8YylajMwsu7Lse!vC/4AD1hVRSPqcwTGEHRnCBcgtrz3Y1UDpWtMDkMkhDePV1Oyg7cNtpLg+P2Z14ng2l9IL8Gw/0= X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:5218 Date: 2005-09-27T18:54:54-07:00 List-Id: "David Trudgett" wrote in message news:m31x3b6n5v.fsf@rr.trudgett... > > Hi all, > > 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. > > Thanks. > > David > If you're just looking for simple code, I would suggest using the Index and Delete functions in Ada.Strings.Unbounded. Something along the lines of: loop deleteIndex := Index( source, charSet, test => outside ); exit when deleteIndex = 0; Delete( source, deleteIndex ); end loop; It's not very efficient, but I think it is about as simple as you can get. You can probably use Find_Token to get rid of consecutive chunks of characters you want to remove, but it would be a little bit more messy (and efficient). Steve (The Duck) > -- > > David Trudgett > http://www.zeta.org.au/~wpower/ > > We must learn to live together as brothers or perish together as > fools. > > -- Martin Luther King, Jr. >