The array argument is an array of ints not objects, hence the String.Format(string, obj) overload is called, not String.Format(string, obj[])). Try this instead:

1
2
 
string.Format("{0} {1}", Array.map box [|"abc"; "def"|])

This would be the same in C#, btw. Also note that in F# "sprintf" gives you a properly typed formatted-printing function.

Best regards,
Stephan

By on 7/9/2008 9:43 AM ()

I turned to using sprintf but I stumbled on another problem.

I have a fairly big format string and I would like to do something like:

#light
let format_string = "let's say this is my big format string just to say %s"
sprintf format_string "Hello!"

But this is not correct. How can I build a format string for sprintf?

Thanks.

By on 7/10/2008 6:05 AM ()

Because of some compiler magic that goes not the format string needs to be next to the printf function. The idiomatic F# solution to constraint is to create format functions:

1
2
3
4
5
#light

let myformater = sprintf "let's say this is my big format string just to say %s"

let mystring = myformater "Hello!"

But if you really want you string to be seperate you can use a type anontation:

1
2
let (format_string:Printf.StringFormat<string->string>) = "let's say this is my big format string just to say %s"
sprintf format_string "Hello!"
By on 7/10/2008 6:45 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper