Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Format.printf

3 views
Skip to first unread message

Christian Sternagel

unread,
Apr 23, 2007, 6:58:17 AM4/23/07
to caml...@yquem.inria.fr
Is there a possibility to parametrize format-strings.
E.g. I want to provide a function [print_string], that,
given an integer [i], right-aligns a string as if it was
of length [i]. But following code is obviously not
possible:

let print_string i s = Format.printf "%%is\n" i s;;

Since "%%" is a `normal' %. But since I do not know the
needed length in advance I can not write something like

let print_string i s = Format.printf "%10s\n" s;;

Any suggestions?

cheers

christian

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Paolo Donadeo

unread,
Apr 23, 2007, 7:32:47 AM4/23/07
to caml...@yquem.inria.fr
> Any suggestions?

let my_print i s = Printf.printf "%*s" i s

Is this what you mean? In any case search for "*" here:

http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html


Regards,

--
Paolo


Paolo Donadeo, Senior Software Engineer
Studio Associato 4Sigma
Email: p.do...@4sigma.it
~
~
:wq

0 new messages