Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printf and formatting rules

Tags:

printf

f#

I'd like to know if all formatting rules of printf functions currently work (or are implemented) in F# ?

For instance, if I want to align arguments on 9 characters (padding with spaces or 0), I would use:

printfn "%9A %9A" arg1 arg2 //don't seem to work

Thanks!

like image 567
Stringer Avatar asked May 15 '10 01:05

Stringer


People also ask

Is printf () and format () are same?

The key difference between them is that printf() prints the formatted String into console much like System. out. println() but the format() method returns a formatted string, which you can store or use the way you want.

How do printf () format specifiers?

The printf prototype is defined in the <cstdio> header file. When you use the printf() function, it prints the string pointed out by the format to the standard output stdout. The format can also contain some specifiers that start with a % and replace values of variables with the printf() function.

What is %d in formatting?

The %d specifies that the single variable is a decimal integer. The %n is a platform-independent newline character. The output is: The value of i is: 461012. The printf and format methods are overloaded.

What is formatted printf in C?

"printf" is the name of one of the main C output functions, and stands for "print formatted". printf format strings are complementary to scanf format strings, which provide formatted input (lexing aka. parsing).


2 Answers

Do check out the docs

http://msdn.microsoft.com/en-us/library/ee370560(v=VS.100).aspx

(and possibly also these

http://en.wikibooks.org/wiki/F_Sharp_Programming/Input_and_Output

http://blogs.msdn.com/dsyme/archive/2010/01/08/some-tips-and-tricks-for-formatting-data-in-f-interactive-and-a-in-sprintf-printf-fprintf.aspx

)

though I am unclear about the fine points of the spec and implementation, especially regarding the %A specifier, which does various magical things. I'll see what other info I can dig up right now...

like image 124
Brian Avatar answered Sep 23 '22 18:09

Brian


Read the documentation:

http://msdn.microsoft.com/en-us/library/ee370560.aspx

like image 22
Bertrand Marron Avatar answered Sep 26 '22 18:09

Bertrand Marron