From: John English <je@bton.ac.uk>
Subject: Re: CONTRAINT ERROR (was Re: parsing a string)
Date: 2000/01/26
Date: 2000-01-26T13:46:16+00:00 [thread overview]
Message-ID: <388EFB47.EEBF2958@bton.ac.uk> (raw)
In-Reply-To: 86mm2o$3cd$1@nnrp1.deja.com
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
-----------------------------------------------------------------
next prev parent reply other threads:[~2000-01-26 0:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-01-15 0:00 parsing a string Paolo M. Pumilia
2000-01-15 0:00 ` James S. Rogers
2000-01-24 0:00 ` pumilia
2000-01-24 0:00 ` Ehud Lamm
2000-01-24 0:00 ` Stephen Leake
2000-01-26 0:00 ` CONTRAINT ERROR (was Re: parsing a string) pumilia
2000-01-26 0:00 ` John English [this message]
2000-01-26 0:00 ` Roger Racine
2000-01-26 0:00 ` Fraser
2000-01-26 0:00 ` Simon Wright
2000-01-26 0:00 ` Ian Clifton
2000-01-24 0:00 ` parsing a string pumilia
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox