String formatting in Haskell

前端 未结 5 607
一生所求
一生所求 2021-02-05 00:05

What is Haskell\'s equivalent of

string str = string.Format(\"{0} {1}\",10,20); // C#
5条回答
  •  花落未央
    2021-02-05 01:06

    You could use the format function provided by the text-format-simple package:

    import Text.Format
    format "{0} {1}" [show 10, show 20]
    

    This function has the signature:

    format :: String -> [String] -> String
    

    So all you need is provide your parameters as strings.
    Another example:

    format "Some {0} believes that 1 + 1 = {1}." ["people",show 10]
    

提交回复
热议问题