ruby 格式化字符串 浮点数

来源:互联网 发布:网络图标 ppt 下载 编辑:程序博客网 时间:2024/04/30 06:56

在ruby中使用format(或 "%")来格式化string.

例子

"Number is %d" % 12     # Number is 12format("Number is %d" , 12)    # Number is 12"Number is %d, type  is %s"   %  [12, "cat"]     # Number is 12, type is catformat("Number is %d, type  is %s" ,[12, "cat"] )    # Number is 12, type is cat"[%10s]"  %  "cat"                #[       cat]format("[%10s]", "cat")        #[       cat]"[%-10s]"  %   "cat"              #[cat       ]format("[%-10s]","cat")        #[cat       ]

原文链接:http://www.dotnetperls.com/format

0 0
原创粉丝点击