SemanticImportString["string"]
attempts to import a string semantically to give a Dataset object.
SemanticImportString["string",type]
attempts to interpret all elements in the string as being of the specified type.
SemanticImportString["string",{type1,type2,…}]
attempts to interpret elements in successive columns as being of the specified types.
SemanticImportString["string",col1->type1,col2->type2,…]
attempts to interpret elements in the named columns as being of the specified types.
SemanticImportString["string",typespec,form]
puts the result in the specified form.
SemanticImportString
SemanticImportString["string"]
attempts to import a string semantically to give a Dataset object.
SemanticImportString["string",type]
attempts to interpret all elements in the string as being of the specified type.
SemanticImportString["string",{type1,type2,…}]
attempts to interpret elements in successive columns as being of the specified types.
SemanticImportString["string",col1->type1,col2->type2,…]
attempts to interpret elements in the named columns as being of the specified types.
SemanticImportString["string",typespec,form]
puts the result in the specified form.
Details and Options
- SemanticImportString has identical functionality to SemanticImport, except that it takes its input from a string rather than the contents of a file.
- SemanticImportString takes the following options:
-
CharacterEncoding "UTF-8" character encoding in the response body Delimiters Automatic delimiters to insert between elements ExcludedLines {} lines to exclude from result HeaderLines Automatic line numbers to treat as headers MissingDataRules Automatic rules for replacing data to be considered "missing"
Examples
open all close allBasic Examples (6)
SemanticImportString["Date City Sales
2014/1/1 Boston 198
2014/1/1 New York 220
2014/1/1 Paris 215
2014/1/1 London 225
2014/1/1 Shanghai 241
2014/1/1 Tokio 218
2014/1/2 Boston 189
2014/1/2 New York 232
2014/1/2 Paris 211
2014/1/2 London 228
2014/1/2 Shanghai 242
2014/1/2 Tokio 229
2014/1/3 Boston 196
2014/1/3 New York 235"]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 City Sales
2014/1/1 Boston 198
2014/1/1 New York 220
2014/1/1 Paris 215
2014/1/1 London 225
2014/1/1 Shanghai 241
2014/1/1 Tokio 218
2014/1/2 Boston 189
2014/1/2 New York 232
2014/1/2 Paris 211
2014/1/2 London 228
2014/1/2 Shanghai 242
2014/1/2 Tokio 229
2014/1/3 Boston 196
2014/1/3 New York 235", {"Date", "City", "Integer"}]Import only some columns of a string, in the specified format, using column numbers:
SemanticImportString["Date City Sales
2014/1/1 Boston 198
2014/1/1 New York 220
2014/1/1 Paris 215
2014/1/1 London 225
2014/1/1 Shanghai 241
2014/1/1 Tokio 218
2014/1/2 Boston 189
2014/1/2 New York 232
2014/1/2 Paris 211
2014/1/2 London 228
2014/1/2 Shanghai 242
2014/1/2 Tokio 229
2014/1/3 Boston 196
2014/1/3 New York 235", <|1 -> "Date", 3 -> Automatic|>]Import only some columns of a string, in the specified format, using column names:
SemanticImportString["Date City Sales
2014/1/1 Boston 198
2014/1/1 New York 220
2014/1/1 Paris 215
2014/1/1 London 225
2014/1/1 Shanghai 241
2014/1/1 Tokio 218
2014/1/2 Boston 189
2014/1/2 New York 232
2014/1/2 Paris 211
2014/1/2 London 228
2014/1/2 Shanghai 242
2014/1/2 Tokio 229
2014/1/3 Boston 196
2014/1/3 New York 235", <|"Date" -> "Date", "Sales" -> Automatic|>]Import a string as a list of named rows:
SemanticImportString["Date City Sales
2014/1/1 Boston 198
2014/1/1 New York 220
2014/1/1 Paris 215
2014/1/1 London 225
2014/1/1 Shanghai 241
2014/1/1 Tokio 218
2014/1/2 Boston 189
2014/1/2 New York 232
2014/1/2 Paris 211
2014/1/2 London 228
2014/1/2 Shanghai 242
2014/1/2 Tokio 229
2014/1/3 Boston 196
2014/1/3 New York 235", Automatic, "NamedRows"]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 Missing["UnknownData"]:
SemanticImportString["1 2 Unknown
3 4 5
6 Unknown 8", MissingDataRules -> {"Unknown" -> Missing["UnknownData"]}]Options (9)
Delimiters (2)
Specifying the delimiter determines how values are separated:
SemanticImportString["1 2, 3 ; 4, 5 6", "String", "Columns", Delimiters -> ","]//InputFormImport semicolon-delimited values instead:
SemanticImportString["1 2, 3 ; 4, 5 6", "String", "Columns", Delimiters -> ";"]//InputFormDelimiters within quotations are ignored:
SemanticImportString["1 \"2, 3\" ; 4, 5 6", "String", "Columns", Delimiters -> ","]//InputFormExcludedLines (1)
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]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]Applications (3)
Import a list of quantities as a Dataset object:
SemanticImportString["1 meters, 2 kilometers, 3 centimeters"]Import quantities as an array:
SemanticImportString["1 meters, 2 kilometers, 3 centimeters", Automatic, "Columns"]SemanticImportString["S. Africa, Japan, USA", Automatic, "Columns"]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]SemanticImportString[text2, <|"PRICE" -> Automatic|>]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
45,4", Automatic, "Rows"]SemanticImportString, unlike SemanticInterpretation, does only simple, quick inferences. SemanticImportString imports state names as strings:
SemanticImportString["Mississippi", Automatic, "Columns"]SemanticInterpretation imports state names as 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 Automatic type specifies an automatically selected number of columns:
SemanticImportString["Nigeria,1
France,2", Automatic, "Rows", HeaderLines -> 0]An {Automatic} type specifies a single column of automatically selected type:
SemanticImportString["Nigeria,1
France,2", {Automatic}, "Rows", HeaderLines -> 0]//InputFormAutomatic in a type list applies to the corresponding column sequentially:
SemanticImportString["Nigeria,1
France,2", {Automatic, Automatic}, "Rows", HeaderLines -> 0]See Also
SemanticImport SemanticInterpretation Interpreter WolframAlpha ImportString Dataset
Function Repository: AddSemantics
Related Guides
History
Text
Wolfram Research (2014), SemanticImportString, Wolfram Language function, https://reference.wolfram.com/language/ref/SemanticImportString.html.
CMS
Wolfram Language. 2014. "SemanticImportString." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SemanticImportString.html.
APA
Wolfram Language. (2014). SemanticImportString. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SemanticImportString.html
BibTeX
@misc{reference.wolfram_2026_semanticimportstring, author="Wolfram Research", title="{SemanticImportString}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/SemanticImportString.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_semanticimportstring, organization={Wolfram Research}, title={SemanticImportString}, year={2014}, url={https://reference.wolfram.com/language/ref/SemanticImportString.html}, note=[Accessed: 13-June-2026]}