Function IniLikeFile.saveToString

Save object to string using .ini like format.

final string saveToString (
  const(IniLikeFile.WriteOptions) options = exact()
) @trusted const;

Returns

A string that represents the contents of file.

Note

The resulting string differs from the contents that would be written to file via saveToFile in the way it does not add new line character at the end of the last line.

See Also

saveToFile, save

Example

string contents =
`
# Leading comment
[First group]
# Comment inside
Key=Value
[Second group]

Key=Value

[Third group]
Key=Value`;

auto ilf = new IniLikeFile(iniLikeStringReader(contents));
assert(ilf.saveToString(WriteOptions.exact) == contents);

assert(ilf.saveToString(WriteOptions.pretty) ==
`# Leading comment
[First group]
# Comment inside
Key=Value

[Second group]
Key=Value

[Third group]
Key=Value`);

assert(ilf.saveToString(WriteOptions(No.preserveComments, No.preserveEmptyLines)) ==
`[First group]
Key=Value
[Second group]
Key=Value
[Third group]
Key=Value`);

assert(ilf.saveToString(WriteOptions(No.preserveComments, No.preserveEmptyLines, Yes.lineBetweenGroups)) ==
`[First group]
Key=Value

[Second group]
Key=Value

[Third group]
Key=Value`);