Wolfram Computation Meets Knowledge

The Wolfram Language:
Fast Introduction for Programmers

Show additional notes for:
All sections 
Get Started


Strings in the Wolfram Language are indicated by double quotes ("...").

The quotes are not included when strings are output, unless you use InputForm:

"this is a string"


<> joins strings:

"this" <> "is" <> "aaaa" <> "bbb"

Notes for Java programmers:

<> is specifically reserved for joining strings in the Wolfram Language, avoiding the ambiguity of using + for this purpose.

Notes for Python programmers:

<> is specifically reserved for joining strings in the Wolfram Language, avoiding the ambiguity present in Python for using + for this purpose.

Strings can contain any Unicode characters, entered using names like \[Alpha], shortcuts like ESC a ESC, explicit Unicode like \:03b1—or entered from a palette button .

Notes for Python programmers:

Both Python 3 and Wolfram Language strings are Unicode by default. In Python 2, strings are ASCII by default, unless explicitly defined as Unicode.

String patterns use ~~ to combine strings with pattern constructs:

StringReplace["this is a string", Shortest[LetterCharacter ... ~~ "is"] -> "xxx"]

In patterns p... indicates zero or more repetitions of p.
RegularExpression allows compact regex notation.

Notes for Java programmers:

String patterns offer powerful string matching using the Wolfram Language pattern syntax. You can also string match using the Wolfram Language's regular expressions, with a notation very similar to Java's regex support.

Notes for Python programmers:

Wolfram Language string patterns offer powerful string matching using a general-pattern syntax, optimized for readability and intuitiveness. The closest analog in Python is string matching with regex, which works similarly to the Wolfram Language's RegularExpression function.

String templates use `` to indicate "slots" and <* ... *> to indicate expressions to evaluate:

TemplateApply["number `` date: <* Now *>", {56}]

Notes for Java programmers:

TemplateApply performs a similar function to Java's System.out.printf method, but the Wolfram Language uses `` instead of %, doesn't require a type specifier and allows inline computations using <* ... *>.

Notes for Python programmers:

TemplateApply in the Wolfram Language works similarly to Python's % or format function, except inline computations using <* ... *> are not supported in Python.

QUICK REFERENCE: Operations on Strings

Which of the following joins together two strings to form another string?

Which of the following string replacements turns "lead" into "gold"?

Which one uses a template to create a string with the value of x at the current time, labeled by the variable label?

© 2018 Wolfram. All rights reserved.