Quoted, Interpolated and Escaped Strings in Julia
String in Julia is a finite sequence of characters. The string can consist of numerals, common punctual symbols, a single word, a group of words, or a multi-line paragraph. Julia allows us to use and manipulate the data in the strings in many ways. Julia also offers a few high-level features for the strings. Some of these features are further discussed in this article.
Julia offers us to create strings using double-quotes (” “), and triple-quotes (”’ ”’) as well. Double-quoted strings are treated normally but triple-quoted strings have some extra features available to them.
These types of strings are treated normally in Julia like in any other language. Operations like concatenation and interpolation are allowed in double-quoted strings.
These types of strings have special behaviors in Julia which are helpful to create long blocks of text. Triple-quoted strings are useful to use in codes that are indented because they recognize new lines.
A new line after the first triple quotes is not considered:
Interpolation of strings
Doing concatenation on strings sometimes can get inconvenient, to tackle this Julia offers interpolation into string literals using $.
In Julia, the interpolation operation can be done in a part of a string literal using parentheses:
To include any character in the string, we have to place a backslash (\) before it:
We can also escape double-quotes using backslash: