({{, (RefLink[SemanticImportString, paclet:ref/SemanticImportString])["string"] 
attempts to import a string semantically to give a (RefLink[Dataset, paclet:ref/Dataset]) object.}, {, (RefLink[SemanticImportString, paclet:ref/SemanticImportString])["string",type]
attempts to interpret all elements in the string as being of the specified type.}, {, (RefLink[SemanticImportString, paclet:ref/SemanticImportString])["string",{(Subscript[type, 1]),(Subscript[type, 2]),…}]
attempts to interpret elements in successive columns as being of the specified types. }, {, (RefLink[SemanticImportString, paclet:ref/SemanticImportString])["string",\[LeftAssociation](Subscript[col, 1])->(Subscript[type, 1]),(Subscript[col, 2])->(Subscript[type, 2]),…\[RightAssociation]]
attempts to interpret elements in the named columns as being of the specified types.}, {, (RefLink[SemanticImportString, paclet:ref/SemanticImportString])["string",typespec,form]
puts the result in the specified form.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[SemanticImportString, paclet:ref/SemanticImportString]) has identical functionality to (RefLink[SemanticImport, paclet:ref/SemanticImport]), except that it takes its input from a string rather than the contents of a file.

OpenersPrimaryExamplesSection(Spacer1)Examples  (29)

OpenersExampleSection0(Spacer1)Basic Examples  (6)

Import a string semantically:

SemanticImportString["Date\tCity\tSales
2014/1/1\tBoston\t198
2014/1/1\tNew York\t220
2014/1/1\tParis\t215
2014/1/1\tLondon\t225
2014/1/1\tShanghai\t241
2014/1/1\tTokio\t218
2014/1/2\tBoston\t189
2014/1/2\tNew York\t232
2014/1/2\tParis\t211
2014/1/2\tLondon\t228
2014/1/2\tShanghai\t242
2014/1/2\tTokio\t229
2014/1/3\tBoston\t196
2014/1/3\tNew York\t235"]

Import a string as a single column of strings:

SemanticImportString["2014/1/1
2014/1/1
2014/1/1
2014/1/1
2014/1/1
2014/1/1
2014/1/2
2014/1/2
2014/1/2
2014/1/2
2014/1/2
2014/1/2
2014/1/3
2014/1/3","Date"]

Import a string with the specified column types:

SemanticImportString["Date\tCity\tSales
2014/1/1\tBoston\t198
2014/1/1\tNew York\t220
2014/1/1\tParis\t215
2014/1/1\tLondon\t225
2014/1/1\tShanghai\t241
2014/1/1\tTokio\t218
2014/1/2\tBoston\t189
2014/1/2\tNew York\t232
2014/1/2\tParis\t211
2014/1/2\tLondon\t228
2014/1/2\tShanghai\t242
2014/1/2\tTokio\t229
2014/1/3\tBoston\t196
2014/1/3\tNew York\t235",{"Date","City","Integer"}]

Import only some columns of a string, in the specified format, using column numbers:

SemanticImportString["Date\tCity\tSales
2014/1/1\tBoston\t198
2014/1/1\tNew York\t220
2014/1/1\tParis\t215
2014/1/1\tLondon\t225
2014/1/1\tShanghai\t241
2014/1/1\tTokio\t218
2014/1/2\tBoston\t189
2014/1/2\tNew York\t232
2014/1/2\tParis\t211
2014/1/2\tLondon\t228
2014/1/2\tShanghai\t242
2014/1/2\tTokio\t229
2014/1/3\tBoston\t196
2014/1/3\tNew York\t235",<|1->"Date",3->Automatic|>]

Import only some columns of a string, in the specified format, using column names:

SemanticImportString["Date\tCity\tSales
2014/1/1\tBoston\t198
2014/1/1\tNew York\t220
2014/1/1\tParis\t215
2014/1/1\tLondon\t225
2014/1/1\tShanghai\t241
2014/1/1\tTokio\t218
2014/1/2\tBoston\t189
2014/1/2\tNew York\t232
2014/1/2\tParis\t211
2014/1/2\tLondon\t228
2014/1/2\tShanghai\t242
2014/1/2\tTokio\t229
2014/1/3\tBoston\t196
2014/1/3\tNew York\t235",<|"Date"->"Date","Sales"->Automatic|>]

Import a string as a list of named rows:

SemanticImportString["Date\tCity\tSales
2014/1/1\tBoston\t198
2014/1/1\tNew York\t220
2014/1/1\tParis\t215
2014/1/1\tLondon\t225
2014/1/1\tShanghai\t241
2014/1/1\tTokio\t218
2014/1/2\tBoston\t189
2014/1/2\tNew York\t232
2014/1/2\tParis\t211
2014/1/2\tLondon\t228
2014/1/2\tShanghai\t242
2014/1/2\tTokio\t229
2014/1/3\tBoston\t196
2014/1/3\tNew York\t235",Automatic,"NamedRows"]

OpenersExampleSection1(Spacer1)Scope  (4)

Import a string using the given delimiter:

SemanticImportString["1,2,3 1,2,3
1,2,3 1,2,3",Delimiters->" "]

Specify that the first line of the string to import is a header:

SemanticImportString["1 2 3 4
5 6 7 8
1 2 3 4",HeaderLines->1]

Specify that the first and third lines of the given string should be skipped:

SemanticImportString["1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9",ExcludedLines->{1,5}]

Return missing values with the form "Unknown" in the special form (RefLink[Missing, paclet:ref/Missing])["UnknownData"]:

SemanticImportString["1 2 Unknown
3 4 5
6 Unknown 8",MissingDataRules->{"Unknown"->Missing["UnknownData"]}]

OpenersExampleSection2(Spacer1)Options  (12)

OpenersExampleSubsection0(Spacer1)Delimiters  (2)

Specifying the delimiter determines how values are separated:

SemanticImportString["1 2, 3 ; 4, 5 6","String","Columns",Delimiters->","]//InputForm

Import semicolon-delimited values instead:

SemanticImportString["1 2, 3 ; 4, 5 6","String","Columns",Delimiters->";"]//InputForm

Delimiters within quotations are ignored:

SemanticImportString["1 \"2, 3\" ; 4, 5 6","String","Columns",Delimiters->","]//InputForm

OpenersExampleSubsection1(Spacer1)HeaderLines  (2)

If a header is detected, the first element in a column is used:

SemanticImportString["1
2.
3.
4.
",Automatic,"NamedColumns"]

When a header is not detected, the header is an index within a string (such as "column1", "column2"):

SemanticImportString["France, 2m
Nigeria, 3m
Spain, 250cm
Canada, 290mm",Automatic,"NamedColumns"]

Specify the number of header lines explicitly:

SemanticImportString["1
2.
3.
4.
",Automatic,"NamedColumns","HeaderLines"->0]

SemanticImportString["1
2.
3.
4.
",Automatic,"NamedColumns","HeaderLines"->2]

OpenersExampleSubsection2(Spacer1)MissingDataRules  (4)

Replace strings that start with "no" by a missing zero:

SemanticImportString["
1, 235, 411
no rank, 199, none
3, 207, 133
",{"Integer","Integer","Integer"},"Columns",MissingDataRules->{("no"~~___)->0}]

Match inputs by regular expression:

SemanticImportString["
1, USA
abc, France
3, Italy
",Automatic,"Columns",MissingDataRules->{RegularExpression["a.*"]->0}]

Lists of lists of rules are applied column by column:

SemanticImportString["
1, USA
abc, France
3, Italy
",Automatic,"Columns",MissingDataRules->{{RegularExpression["[^0-9]*"]->0},Automatic}]

Rules are applied before interpretation:

SemanticImportString["
S. Africa
US
France
",Automatic,"Columns",MissingDataRules->{"US"->Missing["US caught before interpretation"]},"HeaderLines"->0]

OpenersExampleSubsection3(Spacer1)ExcludedLines  (1)

Specify lines that should not be processed:

SemanticImportString["1
2
3
4
5
6
7
8
9
10
",Automatic,"Columns","ExcludedLines"->Select[Range[10],PrimeQ]]

OpenersExampleSubsection4(Spacer1)ColumnSpans  (3)

Specify where to split columns by the positions of the last characters in each column:

SemanticImportString["
ABC123
DEF456
",Automatic,"Columns",ColumnSpans->{3,6}]

ColumnSpans automatically removes delimiters at column boundaries:

SemanticImportString["
ABC,123
DEF,456
",Automatic,"Columns",ColumnSpans->{4,7}]

Delimiters within columns are ignored:

SemanticImportString["ABC12,3\nDEF45,6",Automatic,"Columns",ColumnSpans->{3,7}]

OpenersExampleSection3(Spacer1)Applications  (3)

Import a list of quantities as a (RefLink[Dataset, paclet:ref/Dataset]) object:

SemanticImportString["1 meters, 2 kilometers, 3 centimeters"]

Import quantities as an array:

SemanticImportString["1 meters, 2 kilometers, 3 centimeters",Automatic,"Columns"]

Import countries:

SemanticImportString["S. Africa, Japan, USA",Automatic,"Columns"]

Get the contents of a file:

text=Import["ExampleData/countries-currency","Text"];

Short[text]

Apply any string transformations to the input file. In this case, the full text is simply set to uppercase:

text2=ToUpperCase[text];

Short[text2]

Import the data contained in the string:

SemanticImportString[text2]

Import the price column only:

SemanticImportString[text2,<|"PRICE"->Automatic|>]

OpenersExampleSection4(Spacer1)Possible Issues  (4)

The interpretation of data depends upon its context. Without further context, "12,3" is interpreted as a date:

SemanticImportString["12,3",Automatic,"Rows"]

In the context of the value "45,4", which is not a valid date, "12,3" is interpreted as two integers:

SemanticImportString["12,3\n45,4",Automatic,"Rows"]

(RefLink[SemanticImportString, paclet:ref/SemanticImportString]), unlike (RefLink[SemanticInterpretation, paclet:ref/SemanticInterpretation]), does only simple, quick inferences. (RefLink[SemanticImportString, paclet:ref/SemanticImportString]) imports state names as strings:

SemanticImportString["Mississippi",Automatic,"Columns"]

(RefLink[SemanticInterpretation, paclet:ref/SemanticInterpretation]) imports state names as (RefLink[Entity, paclet:ref/Entity]) objects:

SemanticInterpretation["Mississippi"]

Automatic type selection chooses from a smaller set of interpretations rather than specifying a type explicitly:

SemanticImportString["Mississippi",Automatic,"Columns"]

SemanticImportString["Mississippi","River","Columns"]

An (RefLink[Automatic, paclet:ref/Automatic]) type specifies an automatically selected number of columns:

SemanticImportString["Nigeria,1\nFrance,2",Automatic,"Rows",HeaderLines->0]

An {(RefLink[Automatic, paclet:ref/Automatic])} type specifies a single column of automatically selected type:

SemanticImportString["Nigeria,1\nFrance,2",{Automatic},"Rows",HeaderLines->0]//InputForm

(RefLink[Automatic, paclet:ref/Automatic]) in a type list applies to the corresponding column sequentially:

SemanticImportString["Nigeria,1\nFrance,2",{Automatic,Automatic},"Rows",HeaderLines->0]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[SemanticImport, paclet:ref/SemanticImport])  ▪  (RefLink[SemanticInterpretation, paclet:ref/SemanticInterpretation])  ▪  (RefLink[Interpreter, paclet:ref/Interpreter])  ▪  (RefLink[WolframAlpha, paclet:ref/WolframAlpha])  ▪  (RefLink[ImportString, paclet:ref/ImportString])  ▪  (RefLink[Dataset, paclet:ref/Dataset])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Converting between Expressions & Strings, paclet:guide/ConvertingBetweenExpressionsAndStrings])}, {▪(RefLinkPlain[Free-Form & External Input, paclet:guide/FreeFormAndExternalInput])}, {▪(RefLinkPlain[Text Manipulation, paclet:guide/ProcessingTextualData])}, {▪(RefLinkPlain[Linguistic Data, paclet:guide/LinguisticData])}})}})