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,8bb44fc57f6db2f2 X-Google-Attributes: gid103376,public From: reason67@my-deja.com Subject: Re: Number into String Date: 2000/01/06 Message-ID: <852crn$umf$1@nnrp1.deja.com>#1/1 X-Deja-AN: 569011598 References: <8517up$t0m$1@green.kreonet.re.kr> <851a0e$tp7$1@green.kreonet.re.kr> X-Http-Proxy: NetCache@www-blv-proxy4.boeing.com: Version NetApp Release 3.4D6: Mon Aug 23 16:40:19 PDT 1999-Solaris, 1.0 x24.deja.com:80 (Squid/1.1.22) for client 12.13.226.14 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Thu Jan 06 15:37:29 2000 GMT X-MyDeja-Info: XMYDJUIDreason67 Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.05 [en]C-Boeing Kit (Win95; I) Date: 2000-01-06T00:00:00+00:00 List-Id: In article <851a0e$tp7$1@green.kreonet.re.kr>, "Jeong, Lae Hyung" wrote: > I've found !! > > S : String := Integer'Image(NUM); This thread is kinds fortunate for me to ask a question. I often have the case where I need to put a number into a string of fixed length. I have written a routine to do this that I have been using and re-writing (as I change jobs) since 1989. I was curious if there is an easier way to do this in Ada 95. Here are the two routines required: -- -- PROCESSING: -- This suprogram returns a copy of the original string with all -- the space ' ' characters removed. -- function Strip_Spaces (Str : in String) return String is Result : String (1 .. Str'Length); Last : Integer := 0; begin -- -- Loop through Str and move all characters that are not a ' ' -- into the Result -- for Index in Str'Range loop if Str (Index) /= ' ' then Last := Last + 1; Result (Last) := Str (Index); end if; end loop; return Result (1 .. Last); end Strip_Spaces; ---------- ---------- -- -- PROCESSING: -- This suprogram returns a fixed length string (Length) -- representing Number. Any additional space in the returned -- string can either be set as a zero ('0') if Show_Leading_Zeros -- = True or as a space (' ') if Show_Leading_Zeros = False. If -- the length of Number String is greater than the Length provided, -- the left most portion of the Number that can fit in the result -- is returned. -- function String_Of (Number : in Integer; Length : in Integer; Show_Leading_Zeros : in Boolean := True) return String is Number_String : constant String := Strip_Spaces (Integer'Image (Number)); Result : String (1 .. Length); begin -- -- Fill with leading zero's or spaces as requested -- if Show_Leading_Zeros then Result := (others => '0'); else Result := (others => ' '); end if; -- -- Assign the number to the end of the string -- if Number_String'Length > Length then Result := Number_String (Number_String'Last - Length + 1 .. Number_String'Last); else Result (Length - Number_String'Length + 1 .. Length) := Number_String; end if; return Result; end String_Of; ---------- ---------- --- Jeffrey Blatt Sent via Deja.com http://www.deja.com/ Before you buy.