sprintf and printf and printfn, Oh My!

Compile-time string interpolation is one of the many language benefits of F# that has made the language quite a joy for me to work in so far.

However I have found it difficult to get all of the various *print* (read: “star print star”) methods straight in my head, and I could never find any sort of exhaustive listing of the various methods and their purposes. However as soon as I prepared to make this blog post I found exactly such an exhaustive list from MSDN, here.

To summarize (perhaps just for my own personal benefit), the purposes printf and printfn are generally easy to internalize: they print to stdout.

The function I seem to most frequently need (having moved on past the simple “Hello World”-style console apps) is sprintf, which returns a string itself.

It becomes clear on reviewing the article that there is a pattern to the function naming, with the first and last characters being significant. I recommended perusing the article.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s