Unit 'sysutils' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#rtl]

SScanf

Scan a string for substrings and return the content of these substrings as typed values.

Declaration

Source position: sysstrh.inc line 262

function SScanf(

  const s: string;

  const fmt: string;

  const Pointers: array of Pointer

):Integer;

Description

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:

d
Placeholder for a decimal number.
f
Placeholder for a floating point number (an extended)
s
Placeholder for a string of arbitrary length.
c
Placeholder for a single character

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:

d
A pointer to an integer.
f
A pointer to an extended.
s
A pointer to an ansistring.
c
A pointer to a single character.

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 found values.

Errors

No error checking is performed on the type of the memory location.

See also

Format

  

Format a string with given arguments.

Example

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.

Documentation generated on: Dec 24 2024