Scan a string for substrings and return the content of these substrings as typed values.
Source position: sysstrh.inc line 278
function SScanf( |
const s: string; |
const fmt: string; |
const Pointers: array of Pointer |
):SizeInt; |
SScanF does in essence the opposite of Format: it scans the string S for the elements specified in Fmt, and returns the value of the found elements in the memory locations pointed to by the addresses in Pointers. The Fmt can contain placeholders of the form %X where X can be one of the following characters:
%% matches a single % character in S. A space in Fmt matches any number of spaces in S, including none. Any other character in Fmt must match the character at the current position in S: on a mismatch, scanning stops.
The Pointers array contains a list of pointers, each pointer should point to a memory location of a type that corresponds to the type of placeholder in that position:
On return, these locations will be filled with the actual values found in S for the placeholders in fmt.
The return value of the function is the number of values that were converted and assigned. Scanning stops at the first placeholder that cannot be converted or at the first literal character that does not match, so the result is less than the number of placeholders if S does not match Fmt completely. Literal characters after the last placeholder are not checked: SScanf('(1, 2', '(%d, %d)', [@a,@b]) returns 2. Placeholders that were not converted leave their memory location unchanged.
No error checking is performed on the type of the memory location. An EFormatError exception is raised if Fmt contains an unknown placeholder. An EConvertError exception is raised if a number is out of range for its type.
|
Format a string with given arguments. |
Program Example98; {$mode objfpc} {$h+} { This program demonstrates the function } Uses sysutils; var count,i: Integer; f: Extended; s: String; begin count:=SScanf('234 32.4 hello','%d %f %s',[@i,@f,@s]); writeln(count,' ',i,' ',f,' ',s); End.