Strings in Julia

20 Apr, 2020
Strings in Julia are a set of characters or a single character that is enclosed within double quotes(” “). It is a finite sequence of characters. Julia allows extracting elements of a string to form multiple substrings with the use of square brackets([ ]).
Strings in Julia can be created using double quotes and triple quotes.
# Julia Program for # Creation of String   # Creating a String # with double Quotes String1 = "Welcome to the Geeks World"println("String with the use of Double Quotes: ") println(String1)   # Creating a String # with triple Quotes String1 = """I'm a Geek and I live in a world of Geeks"""println("\nString with the use of Triple Quotes: ") println(String1)   # Creating String with triple # Quotes allows multiple lines String1 ="""Geeks             For             Life"""println("\nCreating a multiline String: ") println(String1) 
Output:
Julia allows extracting characters by accessing a String with the use of Indexing. To extract a character, just pass the index value or a range of values in square brackets([]). While accessing an index out of the range will cause a BoundsError. Only Integers are allowed to be passed as an index, float or other types will also cause a BoundsError.
# Julia Program to Access # characters of String     String1 = "GeeksForGeeks"println("Initial String: ") println(String1)     # Printing First character println("\nFirst character of String is: ") println(String1[1])     # Printing Last character println("\nLast character of String is: ") println(String1[end]) 
Output:
Slicing of a String is done to access a range of characters in a String. It is done by passing a range of Index values with the use of a Slicing Operator(colon) within the square brackets([]).
# Julia Program to Access # characters of String     String1 = "GeeksForGeeks"println("Initial String: ") println(String1)   # Printing 1st to 5th character println("\nSlicing characters from 1-5: ") println(String1[1:5])     # Printing characters between  # 4th and 3rd last character println("\nSlicing characters between ",          "4th and 3rd last character: ") println(String1[4:end-2]) 
The concatenation of strings is the process of adding two or more strings together to form one single string. Concatenation of Strings in Julia can be done in a very simple way by using string(str1, str2, ...) function.
# Julia Program to concatenate# two or more strings  # Declaring String 1String1 = "Geeks"println("String1: ") println(String1)   # Declaring String 2String2 = "for"println("\nString2: ") println(String2)   # Declaring String 3String3 = "Geeks"println("\nString3: ") println(String3)   # String concatenation functionString4 = string(String1, String2, String3)  # Final String after concatenationprintln("\nFinal String:")println(String4)
Output:
Interpolation of Strings is the process of substituting variable values or expressions in a String. It is a process of combining strings but without using the method of concatenation. Interpolation is basically the process of executing whatever that is executable in a string. In Julia, a dollar sign($) is used to insert the value of a variable in the string.
# Julia Program to for# Interpolation of Strings  # Declaring a string str1 = "Geek"  # Declaring a Numberscore = 47  # Interpolation of StringString = "Hello $str1, your score is $score"  # Printing Final Stringprintln(String)
Output:
Julia-dataTypes
Julia
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.