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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,364deb6698b494cb X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-01 07:04:13 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!cyclone.swbell.net!bos-service1.ext.raytheon.com!dfw-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3B17A0DB.6B1B7F09@raytheon.com> From: Mark Johnson Reply-To: mark_h_johnson@raytheon.com X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.2-2smp i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada String Issue: String within Strings References: <4713a80b.0106010531.7f6f4da8@posting.google.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 01 Jun 2001 09:04:11 -0500 NNTP-Posting-Host: 192.27.48.41 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.raytheon.com 991404252 192.27.48.41 (Fri, 01 Jun 2001 09:04:12 CDT) NNTP-Posting-Date: Fri, 01 Jun 2001 09:04:12 CDT Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:7970 Date: 2001-06-01T09:04:11-05:00 List-Id: Xcalibre wrote: > Just a little hello and little comment that I've enjoyed reading > through this newsgroup. > > My problem is this: I am Get_Line-ing from a file... what I want to > do is check that line of text for a particular phrase given (not just > a word). I've tried using Index() and I get an Error that says... > > extract.adb:73:66: array type required in indexed component > > The code reads: > Get_Line (f_From, LineItem, Index); > while (not End_Of_File(f_From)) loop > Found := 0; > Found := Index (LineItem(1..Index), Catch); > if Found > 0 then > Put_Line(f_To, LineItem(1..Index)); > end if; > end loop; > > where > LineItem, Catch : String(1..1024); > Found : Natural; > > Is what I am doing the right idea or is there a different built in > function that will do what C does in comparing the text and returning > the location of where it starts? > > Thanks in advance > Andrew I assume you are using GNAT. Try changing the name of your "Index" variable to something else. The following code... with Ada.Strings.Fixed; use Ada.Strings.Fixed; procedure A is LineItem : String(1..10) := " ABC "; Catch : String(1..10) := "ABC "; Jndex : Natural := 3; Found : Natural; begin Found := Index (LineItem(1..Jndex), Catch); end A; does not have the same problem. Note that I renamed the local "Index" to "Jndex" for this to work. An alternative is... with Ada.Strings.Fixed; use Ada.Strings.Fixed; procedure A is LineItem : String(1..10) := " ABC "; Catch : String(1..10) := "ABC "; Index : Natural := 3; Found : Natural; begin Found := Ada.Strings.Fixed.Index (LineItem(1..Index), Catch); end A; which is a little more explicit on "which Index" you are referring to. --Mark [and yes, I noticed I probably have the LineItem and Catch values assigned wrong....]