exception Scan_failure of
val bscanf :
Scanning.scanbuf -> ('a, Scanning.scanbuf, 'b) format -> 'a -> 'b
bscanf ib format freads tokens from the scanning buffer
ibaccording to the format string
format, converts these tokens to values, and applies the function
fto these values. The result of this application of
fis the result of the whole construct.
Scanf.Scan_failure if the given input does not match the format.
Failure if a conversion to a number is not possible.
End_of_file if the end of input is encountered while scanning
and the input matches the given format so far.
The format is a character string which contains three types of objects:
Conversion specifications consist in the
% character, followed
by optional field width, followed by one or two conversion
characters. The conversion characters and their meanings are:
d: reads an optionally signed decimal integer.
i: reads an optionally signed integer (usual input formats for hexadecimal (
0X[d]+), octal (
0o[d]+), and binary
0b[d]+notations are understood).
u: reads an unsigned decimal integer.
X: reads an unsigned hexadecimal integer.
o: reads an unsigned octal integer.
s: reads a string argument (by default strings end with a space).
S: reads a delimited string argument (delimiters and special escaped characters follow the lexical conventions of Caml).
c: reads a single character.
C: reads a single delimited character (delimiters and special escaped characters follow the lexical conventions of Caml).
G: reads an optionally signed floating-point number in decimal notation, in the style
b: reads a boolean argument (
lo: reads an
int32argument to the format specified by the second letter (decimal, hexadecimal, etc).
no: reads a
nativeintargument to the format specified by the second letter.
Lo: reads an
int64argument to the format specified by the second letter.
[ range ]: reads characters that matches one of the characters mentioned in the range of characters
range(or not mentioned in it, if the range starts with
^). Returns a
stringthat can be empty, if no character in the input matches the range.
fto the number of characters read so far.
%: matches one
%character in the input.
%6dreads an integer, having at most 6 decimal digits; and
%4freads a float with 4 characters.
Scanning indications appear just after string conversions
[ range ] to delimit the end of the token. A scanning
indication is introduced by a
@ character, followed by some
c. It means that the string token should end
just before the next matching
c. If no
c character is
encountered, the string token spreads as much as possible.
"%s@\t" reads a string up to the next tabulation
character. If a scanning indication
@c does not follow a
string conversion, it is ignored and treated as a plain
scanf facility is not intended for heavy duty
lexical analysis and parsing. If it appears not expressive
enough for your needs, several alternative exists: regular expressions
Str), stream parsers,
val fscanf :
Pervasives.in_channel -> ('a, Scanning.scanbuf, 'b) format -> 'a -> 'b
Scanf.bscanf, but inputs from the given channel.
val sscanf :
string -> ('a, Scanning.scanbuf, 'b) format -> 'a -> 'b
Scanf.bscanf, but inputs from the given string.
val scanf :
('a, Scanning.scanbuf, 'b) format -> 'a -> 'b
Scanf.bscanf, but inputs from
stdin(the standard input channel).
val kscanf :
(Scanning.scanbuf -> exn -> 'a) ->
('b, Scanning.scanbuf, 'a) format -> 'b -> 'a
Scanf.bscanf, but takes an additional function argument
efthat is called in case of error: if the scanning process or some conversion fails, the scanning function aborts and applies the error handling function
efto the scanning buffer and the exception that aborted evaluation.