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!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed.pacific.net.au!nasal.pacific.net.au!not-for-mail Newsgroups: comp.lang.ada Subject: Re: String filtering From: David Trudgett Organization: Very little? References: <433bf44d$0$26212$9b4e6d93@newsread2.arcor-online.net> Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:yxG6EP8enjWN+ivDElXiKlccmYg= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 02 Oct 2005 16:38:11 +1000 NNTP-Posting-Host: 61.8.39.61 X-Complaints-To: news@pacific.net.au X-Trace: nasal.pacific.net.au 1128235370 61.8.39.61 (Sun, 02 Oct 2005 16:42:50 EST) NNTP-Posting-Date: Sun, 02 Oct 2005 16:42:50 EST Xref: g2news1.google.com comp.lang.ada:5331 Date: 2005-10-02T16:38:11+10:00 List-Id: tmoran@acm.org writes: > I've missed part of this thread. Was "Fixed" something like: > function Strip_Non_Alphanumeric (Str: in String) return String is > Result : String(Str'range); > Last : Natural := Result'first-1; > begin > for i in Str'range loop > if not Is_In(Str(i), Alphanumeric_Set) then > Last := Last+1; > Result(Last) := Str(i); > end if; > end loop; > return Result(Result'first .. Last); > end Strip_Non_Alphanumeric; Your version looks very neat and concise. It looks correct, though I haven't actually compiled and tested it. The version I actually have now is: function Strip_Non_Alphanumeric (Str : in String) return String is New_Str : String(1 .. Ada.Strings.Fixed.Count(Str, Alpha_Num_Space_Set)); Dest_Char : Natural := 0; begin if New_Str'Last > 0 then for Src_Char in Str'Range loop if Is_In(Str(Src_Char), Alpha_Num_Space_Set) then Dest_Char := Dest_Char + 1; New_Str(Dest_Char) := Str(Src_Char); end if; end loop; else New_Str := ""; end if; return New_Str; end Strip_Non_Alphanumeric; Your version is probably better (lower complexity, greater efficiency). David -- David Trudgett http://www.zeta.org.au/~wpower/ The governor delivers an address in which he demands submission. The excited crowd, generally deluded by their leaders, don't understand a word of what the representative of authority is saying in the pompous official language, and their excitement continues. Then the governor announces that if they do not submit and disperse, he will be obliged to have recourse to force. If the crowd does not disperse even on this, the governor gives the order to fire over the heads of the crowd. If the crowd does not even then disperse, the governor gives the order to fire straight into the crowd; the soldiers fire and the killed and wounded fall about the street. -- Leo Tolstoy, "The Kingdom of God is Within You"