Browse thread
sprintf-Bug?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jonathan Roewen <jonathan.roewen@g...> |
| Subject: | Re: [Caml-list] sprintf-Bug? |
I gave the example :P "%02X" prints a number as hex, 2 chars in length (assuming no more than 2 chars wide), padded with zeroes. Same as you'd do in any other lang with C-style printf. On 2/4/07, Oliver Bandel <oliver@first.in-berlin.de> wrote: > On Sun, Feb 04, 2007 at 02:11:43PM +1300, Jonathan Roewen wrote: > > Don't think so. I'm pretty sure padding of strings is only with > > spaces. > > The format-string "%02s" should make a '0' instead of ' ' > as filling, IMHO. > > > > Padding of numbers has to be specified for a number format. > > IMHO "%2s" should make a string of at least two chars > length, fillingup with ' ' on the left side. > > And "%0s" should make it with a filling-char '0' > instead of filling-chars ' '. > > > > > > > let hex_of_byte b = Printf.sprintf "%02X" b;; > > > > Why you'd use two sprintfs is the real oddity =P > > The inner sprintf makes hex from int and the outer > makes two-char-string instead of one-char-string. > > Or how to make hex-output with filling '0' instead > of ' ' for two-char length strings? > > Would a "%00X" work?! > > > Ciao, > Oliver > > _______________________________________________ > 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 >