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,f82a3047082dd83e X-Google-Attributes: gid103376,public From: sparre@meyer.fys.ku.dk (Jacob Sparre Andersen) Subject: Re: Newbie Q: Zero fill in Put Date: 1997/09/02 Message-ID: <1997Sep2.142611.4003@news.nbi.dk>#1/1 X-Deja-AN: 269551510 References: <340B809C.24AE@home.com> Newsgroups: comp.lang.ada Date: 1997-09-02T00:00:00+00:00 List-Id: Larry Coon (lmcoon@home.com) wrote: __________ | I looked through the docs I have & the FAQ | on Ada Home, but I didn't see an answer to | what I hope is a simple question. How does | one zero-fill for integers in a Put call? ^^^^^^^^^^ |^^^^^^^^^^ | How do I make it output with leading zeros, | eg: 02, 002, 00000002, etc? The width parameter | seems to only fill with spaces. |__________ I do not think there is a routine to do it in the standard libraries, but it is not hard to implement with a few calls to routines in the standard libraries. (warning: untested, uncompiled, and probably incorrect code) with Ada.Strings.Fixed; with Ada.Text_IO; generic type Num is range <>; Fill : Character := '0'; procedure Put (File : in Ada.Text_IO.File_Type; Item : in Num; Fill_To : in Positive) is use Ada.Strings; use Ada.Strings.Fixed; use Ada.Text_IO; Buffer : String (1 .. Fill_To); begin -- Put Move (Target => Buffer, Source => Trim (Item'Image, Both), Pad => Fill, Justify => Right); Put (File => File, Item => Buffer); end Put; Greetings, Jacob -- Jacob Sparre Andersen Web: http://fys.ku.dk/%7Esparre/ Center for Chaos and Turbulence Studies Phone: (+45) 39 65 53 51 The Niels Bohr Institute (+45) 35 32 53 05 -- Try Ada 95 - The programming language of today - and tomorrow!