English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-02-04 (01:51)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] sprintf-Bug?
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?!