Quoted, Interpolated and Escaped Strings in Julia
Last Updated :
25 Aug, 2020
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.
Quoted Strings
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.
Double-quoted strings
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.
Julia
s1 = "Geeks"
s2 = "for"
s3 = "geeks"
s = "s1, s2, s3"
|
Triple-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 $.
Julia
s1 = "Geeks"
s2 = "for"
s3 = "geeks"
"$s1 $s2 $s3"
|
In Julia, the interpolation operation can be done in a part of a string literal using parentheses:
Escaped strings
To include any character in the string, we have to place a backslash (\) before it:
Julia
print ( "I want 1000\$ in my bank account" )
|
We can also escape double-quotes using backslash:
Julia
str = "This is \"Geeksforgeeks\"."
print ( str )
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...