Recently, some tests were conducted in Erlang shell. In order to make the test result data more intuitive, we wanted to align the data to be printed and achieve the same effect as imaging tables.
The idea was to insert a tab in the data. Of course, Erlang also supports tabs, but the actual effect is not satisfactory.
Tab support is as follows:
1> IO: Format ("No1 ~ Sn2 ~ N1 ~ S2 ~ N ", [" \ t "," \ t "]).
No1 no2
1 2
OK
However, if the data length exceeds 8 characters, is there a way to customize the number of alignment characters?
Yes, IO: format/2 pairs ~ S also supports ~ NS, N can be a positive integer or a negative integer. The effect is as follows:
2> IO: Format ("~ -10 s ~ -10 s ~ -10 s ~ -10 s ~ N ", [" No1 "," NO2 "," NO3 "," No4 "]), IO: Format ("~ -10 s ~ -10 s ~ -10 s ~ -10 s ~ N ", [" 123 "," 456789 "," 012 "," 345678901 "]).
No1 NO2 NO3 No4
123 456789 012 345678901
OK
3> IO: Format ("~ 10 s ~ 10 s ~ 10 s ~ 10 s ~ N ", [" No1 "," NO2 "," NO3 "," No4 "]), IO: Format ("~ 10 s ~ 10 s ~ 10 s ~ 10 s ~ N ", [" 123 "," 456789 "," 012 "," 345678901 "]).
No1 NO2 NO3 No4
123 456789 012 345678901
Reference: http://blog.csdn.net/mycwq/article/details/37933111