[GAP Forum] formatted "Print"

R.N. Tsai r_n_tsai at yahoo.com
Thu Sep 1 21:25:35 BST 2016


Dear GAP Forum and Thomas,This is exactly what I need; same functionality as  %6d or %-6d in an even more elegant way.Thanks,R.N. 

      From: Thomas Breuer <sam at Math.RWTH-Aachen.De>
 To: forum at gap-system.org 
 Sent: Thursday, September 1, 2016 5:06 AM
 Subject: Re: [GAP Forum] formatted "Print"
   
Dear GAP Forum,

concerning the question by R.N. Tsai

> Is there a way to do a formatted print in GAP?
> Something equivalent to this for example :  %6d or %-6d  to print an alignedfixed width 6 bit integer....(these are c examples but are used in other languages too).

I would suggest the 2-argument version of 'String',
which creates left or right aligned strings,
depending on
and fills up with whitespace.

Here is an example.

    gap> for i in [ 1 .. 6 ] do Print( String( 10^i, 6 ), "\n" ); od;
        10
      100
      1000
    10000
    100000
    1000000
    gap> for i in [ 1 .. 6 ] do Print( String( 10^i, -6 ), ".\n" ); od;
    10    .
    100  .
    1000  .
    10000 .
    100000.
    1000000.

All the best,
Thomas


_______________________________________________
Forum mailing list
Forum at mail.gap-system.org
http://mail.gap-system.org/mailman/listinfo/forum

   


More information about the Forum mailing list