Open In App

Get repetition of a string in Julia – repeat() Method

Last Updated : 26 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The repeat() is an inbuilt function in julia which is used to return a string which is the repetition of specified string with specified number of times.

Syntax:
repeat(String::AbstractString, r::Integer)

Parameters:

  • String: Specified string or character
  • r::Integer: Specified number of times

Returns: It returns a string which is the repetition of specified string with specified number of times.

Example 1:




# Julia program to illustrate 
# the use of String repeat() method
  
# Create a repetition of string "gfg"
# with 3 times of repetition.
println(repeat("gfg", 3))
  
# Create a repetition of character "a"
# with 4 times of repetition.
println(repeat("a", 4))
  
# Create a repetition of string "Geeks"
# with 2 times of repetition.
println(repeat("Geeks", 2))
  
# Create a repetition of string "@#"
# with 3 times of repetition.
println(repeat("@#", 3))


Output:

gfggfggfg
aaaa
GeeksGeeks
@#@#@#

Example 2:




# Julia program to illustrate 
# the use of String repeat() method
   
# Create a repetition of string "123"
# with 3 times of repetition.
println(repeat("123", 3))
   
# Create a repetition of string "22"
# with 4 times of repetition.
println(repeat("22", 4))
   
# Create a repetition of string "03210"
# with 2 times of repetition
println(repeat("03210", 2))


Output:

123123123
22222222
0321003210


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads