From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id E9E8DBC69 for ; Wed, 27 Jun 2007 05:38:12 +0200 (CEST) Received: from sccmmhc91.asp.att.net (sccmmhc91.asp.att.net [204.127.203.211]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5R3cCWD008608 for ; Wed, 27 Jun 2007 05:38:12 +0200 Received: from [192.168.0.104] (12-208-242-210.client.mchsi.com[12.208.242.210]) by sccmmhc91.asp.att.net (sccmmhc91) with SMTP id <20070627033810m9100d3umpe>; Wed, 27 Jun 2007 03:38:11 +0000 In-Reply-To: <0AC5F6BF-D076-4561-B015-70E41954D248@lrde.epita.fr> References: <0AC5F6BF-D076-4561-B015-70E41954D248@lrde.epita.fr> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: <7A72D27B-4FF3-4483-8D42-B9904FA734E2@valdosta.edu> Cc: caml-list@inria.fr Content-Transfer-Encoding: quoted-printable From: Jonathan Bryant Subject: Re: [Caml-list] precision not working properly for strings in Printf? Date: Tue, 26 Jun 2007 23:38:02 -0400 To: =?ISO-8859-1?Q?Qu=F4c_Peyrot?= X-Mailer: Apple Mail (2.752.3) X-Miltered: at concorde with ID 4681DBA4.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; printf:01 printf:01 specifier:01 prefixing:01 sprintf:01 sprintf:01 beginner's:01 ocaml:01 bug:01 26,:98 2007,:98 beginners:01 wrote:01 integer:01 integer:01 On Jun 26, 2007, at 11:18 PM, Qu=F4c Peyrot wrote: > It seems that the precision field doesn't work properly with the =20 > "s" type in Printf.printf: It does work properly. It's just not working the way you're =20 expecting it to work. > > # Printf.printf "%.2s" "qwerty";; > qwerty- : unit =3D () > > This should print "qw" No it shouldn't. The width/precision specifier guarantees a =20 _minimum_ length for strings, not an absolute length. =46rom the docs =20= for Printf: "The optional width is an integer indicating the minimal width of the =20= result. For instance, %6d prints an integer, prefixing it with spaces =20= to fill at least 6 characters. The optional precision is a dot . followed by an integer indicating =20 how many digits follow the decimal point in the %f, %e, and %E =20 conversions. For instance, %.4f prints a float with 4 fractional =20 digits." Minimal length for width and precision doesn't apply to string =20 conversions. Here's how it works: Objective Caml version 3.09.3 # Printf.sprintf "%2s" "qwerty";; - : string =3D "qwerty" # Printf.sprintf "%.2s" "qwerty";; - : string =3D "qwerty" # Printf.sprintf "%5s" "a";; - : string =3D " a" # Printf.sprintf "%.5s" "a";; - : string =3D " a" Hope that helps. --Jonathan > > --=20 > Best Regards, > Qu=F4c > _______________________________________________ > 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