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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,28998cd551b69db0 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-28 19:38:16 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!intern1.nntp.aus1.giganews.com!nntp.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 28 Dec 2003 21:38:14 -0600 Date: Sun, 28 Dec 2003 22:38:13 -0500 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Controlling width of strings during Put operation? References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.34.214.193 X-Trace: sv3-vbDZuyu94hjMbR+0Sg5X8UB7YC0Q70zvv3tDpfDOpYMShT4HfcuiQRu0rXEc3jI/bMQzBtvkx1cFgu/!zD+qxh3VT1M06Zap7xbcCwp3hZpdev6KsjKzUqy2BA8g3u+UTSqH4VGtKAn/Gw== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:3911 Date: 2003-12-28T22:38:13-05:00 List-Id: Peter C. Chapin wrote: > My issue is: how do I best print the table headers? I could certainly > play around with spaces until I got good looking results but that seems > fragile and inelegant. I'd rather set a field width for each header > based on the Num'Width of the numeric type in the column below that > header. That way if I change the type of one of the columns, the headers > have a prayer of still lining up without me fiddling with them again. My > problem is that I don't see a Put procedure that allows me to specify a > field width when I print a string. Do I have to "manually" prepare my > own header strings with the appropriate number of padding spaces? Is > there an easy way to do that? Yes. I would use Ada.Strings.Fixed.Trim (see http://www.adaic.org/standards/95lrm/html/RM-A-4-3.html) with Ada.Strings.Fixed; with Ada.Text_IO; ... function Pad(Header: in String; Size: Positive := Integer'Width) return String is use Ada.Strings, Ada.Strings.Fixed; Result: String(1..Size); begin Move(Source => Header, Target => Result, Drop => Right, Justify => Center, Pad => Space); -- or of course, whatever values you want. return Result; end Pad; Now of course you just write your header line something like: Ada.Text_IO.Put_Line( Pad("Column 1") & Pad("Column 2") & ...); I often think that there should be a function form of Move, in Ada.Strings.Fixed. But since it is usually much more convenient to use the above technique to reset some of the defaults anyway, I don't get too upset about it. -- Robert I. Eachus "The war on terror is a different kind of war, waged capture by capture, cell by cell, and victory by victory. Our security is assured by our perseverance and by our sure belief in the success of liberty." -- George W. Bush