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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,161a2fbfbb989fdf,start X-Google-Attributes: gid103376,public From: Ray Subject: Novice String Question Date: 1999/09/01 Message-ID: #1/1 X-Deja-AN: 519746948 Content-Transfer-Encoding: 8bit X-Orig-Message-ID: <37CD3696.6C3B47F4@airmail7.net> X-Accept-Language: en Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Time: Wed Sep 1 09:22:59 1999 Organization: Airnews.net! at Internet America NNTP-Proxy-Relay: library1.airnews.net Mime-Version: 1.0 Reply-To: crwhite12@airmail7.net Abuse-Reports-To: abuse at airmail.net to report improper postings Newsgroups: comp.lang.ada Date: 1999-09-01T00:00:00+00:00 List-Id: I am working on learning strings, so forgive the creaky code. I can get the �Replace_Slice� to work if Y and Z are the same length, otherwise the last Put_Line will raise an exception. 1. Do I need, and how can I get the Drop and Justify parameters to work? 2. Should I be using something else? 3. How can I convert this to either bounded or unbounded (have not been able to get the declares/withs right)? -- code with Ada.Text_Io, Ada.integer_text_io, Ada.Strings.Fixed; use Ada.Text_Io, Ada.integer_text_io, Ada.Strings.Fixed; -- -- Cohen 'Ada as a 2nd language' 2nd ed. Page 225. -- Exercise 5.2, read a source X, pattern Y, and replace Z strings. -- Replace the first occurrence of the pattern. -- Assume max string length is 80. -- procedure EX5_2 is X, Y, Z: string (1 .. 80); I_X, I_Y, I_Z : Natural; begin get_line (X, I_X); -- get the strings get_line (Y, I_Y); get_line (Z, I_Z); -- find start of first match Flag_InStr := Index(X(X'first .. I_X), Y (Y'first .. I_Y)); If Flag_InStr /= 0 then -- do we have a match? X := Replace_Slice (X, Flag_InStr, Flag_InStr + I_Y - 1, Z(Z'first .. I_Z)); I_X := I_X + (I_Z - I_Y); -- correct X end index for Z and Y not = length end if; put_line (X (X'first .. I_X)); -- echo the modified string end EX5_2; -- Remove the numbers from my address to reply. Ray