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, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1db5f5538715d789 X-Google-Attributes: gid103376,public From: Ted Dennison Subject: Re: integer'image Date: 2000/04/17 Message-ID: <8dflqg$8m1$1@nnrp1.deja.com>#1/1 X-Deja-AN: 612331162 References: <29IK4.5459$sB3.3596@news.indigo.ie> X-Http-Proxy: 1.0 x37.deja.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Mon Apr 17 18:40:19 2000 GMT X-MyDeja-Info: XMYDJUIDtedennison Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.7 [en] (WinNT; I) Date: 2000-04-17T00:00:00+00:00 List-Id: In article <29IK4.5459$sB3.3596@news.indigo.ie>, "NANCY HEHIR" wrote: > for x in 1..20 loop > integer_string:=integer'image(x); > end loop; > > everything is fine until x=10. This raises a constraint error which I > interpret to be a problem with mismatched string lenghts. If I > I'm sure that it is a standard application to convert integers to > their string images but I can't figure what I'm missing here. The problem isn't your integer-string conversion idiom, its your string assignment idiom. You can't expect to be able to assign a varying-length string into a fixed length string. It'll only work if the lengths of the two strings just happen to be equal. There are several ways to save your string image. One is to initialize a constant (or variable) with the string itself, eg: for x in 1..20 loop declare Integer_String : constant String := Integer'image(x); begin ... end; end loop; Another way would be to declare a string big enough to hold the largest value you'll get, and keep track of its length: for x in 1..20 loop Integer_String_Length := String'length(Integer'image(x)); Integer_String(1..Integer_String_Length) := Integer'image(x); end loop; Another would be to use either Ada.Strings.Unbounded.Unbounded_String or Ada.Strings.Bounded.Bounded_String. -- T.E.D. http://www.telepath.com/~dennison/Ted/TED.html Sent via Deja.com http://www.deja.com/ Before you buy.