[GAP Forum] formatted "Print"

Thomas Breuer sam at Math.RWTH-Aachen.De
Thu Sep 1 13:06:00 BST 2016


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




More information about the Forum mailing list