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: Ian Clifton Subject: Re: CONTRAINT ERROR (was Re: parsing a string) Date: 2000/01/26 Message-ID: <4qaeltvtop.fsf@melvin.dp.ox.ac.uk>#1/1 X-Deja-AN: 577830669 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-Complaints-To: newsmaster@ox.ac.uk X-Trace: news.ox.ac.uk 948893945 558 163.1.17.71 (26 Jan 2000 13:39:05 GMT) Organization: Oxford University, England NNTP-Posting-Date: 26 Jan 2000 13:39:05 GMT Newsgroups: comp.lang.ada Date: 2000-01-26T13:39:05+00:00 List-Id: pumilia@est.it writes: > 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); > put(" Output: "); put(output_file); put("<--"); new_line; > put(" index: "); pos1 := Index(output_file,"xxx"); > put(pos1); > new_line; > > end str2_test; > -- str2_test -------------------------------------- > > > While executing i get the error: > > > raised constraint_error : str2_test.adb:24 > > This is line 24: > > output_file := to_string(output_file_string); > > > Any help wil be appreciiated > thank you > Pol I think the problem is that output_file is a fixed-length(=25) string, while Ada.Strings.Unbounded.To_String returns a fixed string of whatever length output_file_string happens to be. This will fail unless that length happens to be 25. In places where you'd like to assign to a fixed-length string, it almost always makes more sense to use Ada.Strings.Fixed.Move instead. Ada.Strings.Fixed.Move pads or truncates appropriately to match the length of the target string. -- Ian Clifton Phone: +44 1865 275631 Dyson Perrins Laboratory Fax: +44 1865 275674 Oxford University OX1 3QY UK ian.clifton@linacre.ox.ac.uk