caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Format.printf
@ 2007-04-23 10:56 Christian Sternagel
  2007-04-23 11:31 ` [Caml-list] Format.printf Paolo Donadeo
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Sternagel @ 2007-04-23 10:56 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Format.printf
  2007-04-23 10:56 Format.printf Christian Sternagel
@ 2007-04-23 11:31 ` Paolo Donadeo
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Donadeo @ 2007-04-23 11:31 UTC (permalink / raw)
  To: caml-list

> 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.donadeo@4sigma.it
~
~
:wq


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-04-23 11:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-23 10:56 Format.printf Christian Sternagel
2007-04-23 11:31 ` [Caml-list] Format.printf Paolo Donadeo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).