SDF: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: SDF
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **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). | |
| 2 | + | ||
| 3 | + | ## SDF format | |
| 4 | + | ||
| 5 | + | A summary of the SDF format as used in [[TStringList]], as paraphrased/synthesized from various versions of Delphi help (e.g. [DelimitedText](http://docwiki.embarcadero.com/Libraries/en/System.Classes.TStrings.DelimitedText), [StrictDelimiter](http://docwiki.embarcadero.com/Libraries/en/System.Classes.TStrings.StrictDelimiter)) | |
| 6 | + | ||
| 7 | + | - 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) | |
| 8 | + | - In addition, a QuoteChar in a string **must** be repeated. | |
| 9 | + | - When setting DelimitedText, strings **must** be separated by Delimiter characters **or** spaces. | |
| 10 | + | - Strings **may** be enclosed in QuoteChars. | |
| 11 | + | - QuoteChars in the string **must** be repeated to distinguish them from the QuoteChars enclosing the string. | |
| 12 | + | - Delimiters that are not contained within QuoteChar marks **must** be handled as delimiters | |
| 13 | + | - If StrictDelimiter is false, spaces that are not contained within QuoteChar marks *'must* be handled as delimiters. | |
| 14 | + | - Two Delimiters in a row indicate an empty string. | |
| 15 | + | ||
| 16 | + | ## Example output | |
| 17 | + | ||
| 18 | + | Example SDF output (tested in Delphi and FPC after applying the patch for issue 19610): | |
| 19 | + | ||
| 20 | + | > **Note:** FPC versions below 2.6.0 do not generate SDF according to the specification | |
| 21 | + | ||
| 22 | + | This series of strings in a stringlist (note: numbers in front indicate the field for clarity, they are not part of the data): | |
| 23 | + | ||
| 24 | + | `0normal_string`\ | |
| 25 | + | `1includes;delimiter`\ | |
| 26 | + | `2includes space`\ | |
| 27 | + | `3includes"quote`\ | |
| 28 | + | `4includes "quote and space`\ | |
| 29 | + | `5tab character`\ | |
| 30 | + | `6"single_starting_quote`\ | |
| 31 | + | `7multi`\ | |
| 32 | + | `line.`\ | |
| 33 | + | `8 SpacesInFront`\ | |
| 34 | + | `9SpacesAtTheEnd` | |
| 35 | + | ||
| 36 | + | gets output as this with *StrictDelimiter* true (and ; as delimiter): | |
| 37 | + | ||
| 38 | + | `normal_string;"includes;delimiter";includes space;"includes""quote";"includes ""quote and space";tab character;"""single_starting_quote";multi`\ | |
| 39 | + | `line.; SpacesInFront;SpacesAtTheEnd ` | |
| 40 | + | ||
| 41 | + | ... and output as this with *StrictDelimiter* false: | |
| 42 | + | ||
| 43 | + | `normal_string;"includes;delimiter";"includes space";"includes""quote";"includes ""quote and space";"tab character";"""single_starting_quote";"multi`\ | |
| 44 | + | `line.";" SpacesInFront";"SpacesAtTheEnd "` | |
| 45 | + | ||
| 46 | + | ## See also | |
| 47 | + | ||
| 48 | + | - [[CSV]] A related format | |
| 49 | + | - [a patch that improved SDF input/output](http://bugs.freepascal.org/view.php?id=19610) | |
| 50 | + | - [[TSdfDataSet]] | |
| 51 | + | ||
| 52 | + | --- | |
| 53 | + | *From the Free Pascal wiki, page "SDF", as it stood on 2017-06-14 after a change by E-ric, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
