String concatenation in Julia is a way of appending two or more strings into a single string whether it is character by character or using some special characters end to end. There are many ways to perform string concatenation.
Example:
Input: str1 = 'Geeks' str2 = 'for' str3 = 'Geeks' Output: 'GeeksforGeeks'
Methods of Concatenation
The different ways in which we can concatenate strings in Julia are :
- Using * operator
- Using ^ operator
- Using string() function
Using ‘*’ operator
It is used to concatenate different strings and/or characters into a single string. We can concatenate two or more strings in Julia using * operator.
Example:
Julia
# creating string 1 s1 = "Hello " # creating string 2 s2 = "World !" # concatenating the strings s = s1 * s2 # printing the concatenated string print(s) |
Output:

Using ‘^’ operator
This operator repeats the specified string with the specified number of times. It is used when there is a need to concatenate a single string multiple times.
Example:
Julia
# creating string s1 = "Hello " # concatenating the string s = s1 ^ 5 # printing the concatenated string print(s) |
Output:

Using string() function
Julia provides a pre-defined string() function for the concatenation of strings. This function takes all the strings to be concatenated as arguments and returns a single concatenated string.
string(string1, string2, string3, string4, …)
Example 1:
Julia
# creating string 1 s1 = "Hello " # creating string 2 s2 = "World !" # concatenating the strings s = string(s1, s2) # printing the concatenated string print(s) |
Output:

Example 2:
Julia
# creating 3 strings s1 = "I"s2 = "Love"s3 = "Julia" # concatenating the strings string(s1, " ", s2, " ", s3) # printing the concatenated string print(s) |
Output:

Storing to a File
Concatenated strings can be stored in a File by using the write() function. Here, firstly the concatenation is done and then the file is first opened into ‘w’ i.e. write mode and the concatenated string is stored with the use of write().
Example:
Julia
# creating 3 strings s1 = "I"s2 = "Love"s3 = "Julia" # concatenating the strings s = s1 * " " * s2 * " " * s3 # storing string s in a file open("myfile.txt", "w") do io write(io, s) end; |
Output:

Recommended Posts:
- Concatenation of arrays in Julia - cat(), vcat(), hcat() and hvcat() Methods
- Julia end Keyword | Marking end of blocks in Julia
- Julia function keyword | Create user-defined functions in Julia
- Julia continue Keyword | Continue iterating to next value of a loop in Julia
- Julia break Keyword | Exiting from a loop in Julia
- Julia local Keyword | Creating a local variable in Julia
- Julia global Keyword | Creating a global variable in Julia
- Convert an Integer to a String in Julia - string() Function
- String Concatenation in R Programming
- Get size of string in Julia - sizeof() Method
- Reverse a string in Julia - reverse() Method
- Get the last occurrence of the specified string pattern in Julia - findlast() Method
- Get length of a string in Julia - length() Method
- Get repetition of a string in Julia - repeat() Method
- Get a substring of specified length from a string in Julia - SubString() Method
- Get the first occurrence of the specified string pattern in Julia - findfirst() Method
- Check if a string contains a non-ASCII value in Julia - ascii() Method
- Replace a substring with another string in Julia - replace() Method
- Check if string starts with a specified prefix in Julia - startswith() Method
- Check if string ends with a specified suffix in Julia - endswith() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

