io:使用参数格式化控制序列字符串

时间:2013-06-26 19:22:20

标签: erlang

  

控制序列的格式是〜F.P.PadModC。如果F,P或Pad为*,则Data中的下一个参数用作F或P的数值。

我在哪里可以找到一些io的例子:带参数控制序列的格式?

2 个答案:

答案 0 :(得分:3)

至少很难找到google搜索。 Erlang文档描述了它,但很难找到代码示例。输出周围的''用于表示空格。

>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  '

希望这有助于像我这样的人。希望看到更多难以找到的例子添加到这篇文章。

答案 1 :(得分:1)

更多例子。

  1. Ç
    • >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
  2. 电子
    • > 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