[
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: | Olivier Andrieu <andrieu@i...> |
| Subject: | Re: [Caml-list] Printf question |
Richard Jones [Friday 26 September 2003] :
>
> I want to write a function which is a bit like Printf.printf, but
> handles the %s placeholder differently. It needs to do SQL-style
> escaping, eg:
>
> my_printf "The string: %s" "string with 'quotes'"
>
> would return the string:
>
> The string: 'string with ''quotes'''
>
> (hope I've got that right ...)
>
> Anyway, it looks like this should be possible, and possibly even quite
> simple, with a custom formatter.
You could use the %a format. See the Prinf module documentation :
* `a': user-defined printer. Takes two arguments and apply the first
one to `outchan' (the current output channel) and to the second
argument. The first argument must therefore have type `out_channel
-> 'b -> unit' and the second `'b'. The output produced by the
function is therefore inserted in the output of `fprintf' at the
current point.
(that's for fprintf, for sprintf the printer would be of type
`unit -> 'b -> string')
--
Olivier
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners