From Free Pascal wiki
Jump to: navigation, search

English (en) français (fr)

SDF is a delimited text file format used in Delphi (and later FreePascal) that is very much like, but not the same, as CSV. (.sdf is also the extension of Microsoft SQL Server data files, therefore it may not be a good idea to use the .sdf extension for your files).

SDF format

A summary of the SDF format as used in TStringList, as paraphrased/synthesized from various versions of Delphi help (e.g. DelimitedText, StrictDelimiter)

  • If you get DelimitedText, strings that include spaces, Delimiter (e.g. ,) or QuoteChar must be enclosed in QuoteChars (" by default) aka quoted. (In practice - read Delphi does this -, however, with StrictDelimiter on, e.g. spaced text is not quoted)
  • In addition, a QuoteChar in a string must be repeated.
  • When setting DelimitedText, strings must be separated by Delimiter characters or spaces.
  • Strings may be enclosed in QuoteChars.
  • QuoteChars in the string must be repeated to distinguish them from the QuoteChars enclosing the string.
  • Delimiters that are not contained within QuoteChar marks must be handled as delimiters
  • If StrictDelimiter is false, spaces that are not contained within QuoteChar marks 'must be handled as delimiters.
  • Two Delimiters in a row indicate an empty string.

Example output

Example SDF output (tested in Delphi and FPC after applying the patch for issue 19610):


Note: FPC versions below 2.6.0 do not generate SDF according to the specification

This series of strings in a stringlist (note: numbers in front indicate the field for clarity, they are not part of the data):

2includes space
4includes "quote and space
5tab	character
8   SpacesInFront

gets output as this with StrictDelimiter true (and ; as delimiter):

normal_string;"includes;delimiter";includes space;"includes""quote";"includes ""quote and space";tab	character;"""single_starting_quote";multi
line.;   SpacesInFront;SpacesAtTheEnd  

... and output as this with StrictDelimiter false:

normal_string;"includes;delimiter";"includes space";"includes""quote";"includes ""quote and space";"tab	character";"""single_starting_quote";"multi
line.";"   SpacesInFront";"SpacesAtTheEnd  "

See also