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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,564a91823edb719c X-Google-Attributes: gid103376,public From: John English Subject: Re: CONTRAINT ERROR (was Re: parsing a string) Date: 2000/01/26 Message-ID: <388EFB47.EEBF2958@bton.ac.uk>#1/1 X-Deja-AN: 577851254 Content-Transfer-Encoding: 7bit References: <388095E5.6BF46237@cstc.org> <85q63n$ese$1@bgtnsc01.worldnet.att.net> <86h42s$1ht$1@nnrp1.deja.com> <86mm2o$3cd$1@nnrp1.deja.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: news@bton.ac.uk X-Trace: saturn.bton.ac.uk 948894376 28447 193.62.183.204 (26 Jan 2000 13:46:16 GMT) Organization: University of Brighton Mime-Version: 1.0 NNTP-Posting-Date: 26 Jan 2000 13:46:16 GMT Newsgroups: comp.lang.ada Date: 2000-01-26T13:46:16+00:00 List-Id: pumilia@est.it wrote: > Here is my test procedure, aimed to converting an unbounded string > to string and then to parse the string: > > -- str2_test -------------------------------------- > [...snip...] > procedure str2_test is > > output_file_string : unbounded_string ; > output_file : string (1..25) ; > pos1 : natural; > > Begin > > get_line(output_file_string); > > put(" output: "); put(output_file_string); put("<--"); new_line; > output_file := to_string(output_file_string); Output_String is exactly 25 characters long, so Output_File_String has to be exactly 25 characters long too. If it isn't, you'll get a Constraint_Error, just as you discovered. Try this: if Length(Output_File_String) > 25 then Output_File := To_String(Output_File_Length)(1..25); else Output_File := (others => ' '); -- to pad result with spaces Output_File(1..Length(Output_File_String)) := To_String(Output_File_Length); end if; (untested, and would be better with the aid of Output_File'Length, Output_File'First and Output_File'Last instead of magic numbers 1 and 25.) ----------------------------------------------------------------- John English | mailto:je@brighton.ac.uk Senior Lecturer | http://www.it.bton.ac.uk/staff/je Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS ** University of Brighton | -- see http://burks.bton.ac.uk -----------------------------------------------------------------