Reputation: 257
The format of a control sequence is ~F.P.PadModC. If F, P, or Pad is *, the next argument in Data is used as the numeric value of F or P.
Where can I find some example of io:format with control sequence with parameters?
Upvotes: 2
Views: 694
Reputation: 135
Some more examples.
>io:format("~*.c",[3,$c]).
>cccok
> io:format("~*.*c",[10,2,$c]). % F=10 , P = 2
> ccok
> io:format("~*.*.-c",[10,2,$c]). % F=10 , P=2 and Pad= -(hyphen)
>--------ccok
> io:format("~*.*./e",[10,2,223.45]). % F= 10 , P =2 and Pad= /(forward slash)
>////2.2e+2ok % unlike f precision in case of e is total number of digits
Upvotes: 1
Reputation: 257
Its hard to find with a google search at least. Erlang docs describes it all but its hard to find code examples. '' around the output are used for representing spaces.
>io:format("'~*s'", [10, "test"]). % right align space padded
>' test'
>io:format("'~*s'", [-10, "test"]). % left align space padded
>'test '
>io:format("'~*B'", [10, 99]). % space padded right aligned integer
>' 99'
>io:format("'~*B'~n", [-10, 88]). % space padded left aligned integer
>'88 '
>io:format("'~*.*f'~n", [-10,5,77.1234]). % left aligned space padded float with precision
>'77.12340 '
Hope this helps someone like me. Wish to see more hard to find example added to this post.
Upvotes: 3