OpenersPrimaryExamplesSection(Spacer1)Examples  (6)

OpenersExampleSection0(Spacer1)Basic Examples  (6)

Export an association as a section with properties:

ExportString[<|"webservers"-><|"tomcat.server.1" -> "host1", "tomcat.server.2" -> "host2"|>|>, "Ini"]

Create a file:

file = CreateFile[];

Add a section and few properties to it:

WriteString[
file, "
[login]
user=root
password=12345"];

Import it as an Ini file:

Import[file, "Ini"]

Create a file:

file = CreateFile[];

Write properties and comments to it:

WriteString[file, "
;An example of a Windows boot.ini
[boot loader]
timeout=40
default=multi(0)disk(0)rdisk(0)partition(1)\\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\\WINDOWS=\"Microsoft Windows XP Professional\" /fastdetect
"];

Import the data only, as an (RefLink[Association, paclet:ref/Association]):

Import[file, "Ini"]

Import the data and the comment:

Import[file, {"Ini", "AnnotatedData"}]

Whitespace characters are not trimmed:

ImportString[" key = value ", "Ini"]

ImportString[";    comment starting with spaces", {"Ini", "AnnotatedData"}]

Sections must start with the character "[" and finish with "]":

ImportString[" [section]", "Ini"]

Commented lines must start with the character ";":

ImportString[" ; comments", "Ini"]

Arbitrary expressions are converted to strings using (RefLink[InputForm, paclet:ref/InputForm]):

ExportString[<|"Section" -> <|"quantity"->Quantity[1,"Hours"]|>|>, "Ini"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {Related Formats:  (RefLink[PHPIni, paclet:ref/format/PHPIni])  ▪  (RefLink[JavaProperties, paclet:ref/format/JavaProperties])  ▪  (RefLink[CSV, paclet:ref/format/CSV])  ▪  (RefLink[TSV, paclet:ref/format/TSV])  ▪  (RefLink[ApacheLog, paclet:ref/format/ApacheLog])  ▪  (RefLink[Text, paclet:ref/format/Text])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Importing & Exporting, paclet:guide/ImportingAndExporting])}, {▪(RefLinkPlain[Listing of All Formats, paclet:guide/ListingOfAllFormats])}, {▪(RefLinkPlain[Systems & Utility Formats, paclet:guide/SystemsAndUtilityFormats])}, {▪(RefLinkPlain[Web Formats, paclet:guide/WebFormats])}})}})