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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4f316de357ae35e9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-01 18:57:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!news.tufts.edu!uunet!dca.uu.net!prodigy.com!newsmst01.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr14.news.prodigy.com.POSTED!3bae8248!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: FAQ and string functions References: <29e5ffff.0208011621.3193755f@posting.google.com> X-Newsreader: Tom's custom newsreader Message-ID: <4Fl29.35056$lH.68650256@newssvr14.news.prodigy.com> NNTP-Posting-Host: 64.175.242.228 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr14.news.prodigy.com 1028253376 ST000 64.175.242.228 (Thu, 01 Aug 2002 21:56:16 EDT) NNTP-Posting-Date: Thu, 01 Aug 2002 21:56:16 EDT Organization: Prodigy Internet http://www.prodigy.com X-UserInfo1: TSU[@SVGXZUWSVPXN[O@_WH@YR_B@EXLLBWLOOAF@YUDUWYAKVUOPCW[ML\JXUCKVFDYZKBMSFX^OMSAFNTINTDDMVW[X\THOPXZRVOCJTUTPC\_JSBVX\KAOTBAJBVMZTYAKMNLDI_MFDSSOLXINH__FS^\WQGHGI^C@E[A_CF\AQLDQ\BTMPLDFNVUQ_VM Date: Fri, 02 Aug 2002 01:56:16 GMT Xref: archiver1.google.com comp.lang.ada:27593 Date: 2002-08-02T01:56:16+00:00 List-Id: > > choice of "Fixed", "Bounded", or "Unbounded"). > I haven't been able to find any documentation on how to use these > functions... The Ada.Strings.* are described in Appendix A of the ALRM (available on-line) and ought to be in any complete Ada textbook. For iterating over tokens Ada.Strings.Fixed.Index might be more convenient, as in: with Ada.Strings.Fixed, Ada.Text_IO; procedure Split is Test : constant String := "These are the times that try men's souls"; Left : Natural := Test'first; Right : Natural; begin while Left <= Test'last loop Right := Ada.Strings.Fixed.Index(Test(Left .. Test'last), " "); if Right = 0 then Right := Test'last+1;end if; Ada.Text_IO.Put_Line(Test(Left .. Right-1)); Left := Right+1; end loop; end Split; >Also something else I have been trying to work out, is how to replace, >say all instances of "/" in a string with, say "__". with Ada.Text_IO, Ada.Strings.Fixed; procedure Rep is Test : constant String := "now is the/a time for all/some good//men/women"; function Replace(Source, Drop, Add : String) return String is -- replace each occurrence of Drop in Source with Add -- Note: The modified string is not rescanned, so, for instance, -- Replace("Hello World", Drop=>" ", Add=>" "); will not -- attempt to insert an infinite number of blanks. Si : Natural := Ada.Strings.Fixed.Index(Source, Drop); begin if Si = 0 then return Source; else return Source(Source'First .. Si - 1) & Add & Replace(Source(Si + Drop'Length .. Source'Last), Drop, Add); end if; end Replace; begin Ada.Text_IO.Put_Line(Replace(Test, Drop => "/", Add => "__")); end Rep;