Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

repeat
string
julia
communitycreator

How to use the repeat string method in Julia

Programming Bytes

Overview

The repeat method in Julia returns a new string whose value is the concatenation of this string repeated n times, where n is passed as an argument.

Syntax

repeat(String::AbstractString, n::Integer)

Arguments

This method takes two arguments.

  1. sourcestr: This is the string to be repeated.
  2. n: This is the integer value denoting the number of times the string is repeated.

Return value

This method returns a string as a return value.

Code example

The code below demonstrates how we can use the repeat method:

#  Repeating the string 3 times
println(repeat("Educative_", 3))
  
#  Repeating the string 4 times
println(repeat("**_", 4))

#  Repeating the string 2 times
println(repeat("hello ", 2))
Using the repeat method

Code explanation

Line 2: We use the repeat method with the Educative_ string and 3 as arguments. The repeat method returns Educative_Educative_Educative_ string as a result.

Line 5: We use the repeat method with the **_ string and 4 as arguments. The repeat method returns **_**_**_**_ as a result.

Line 8: We use the repeat method with the hello string and 2 as arguments. The repeat method returns hello hello as a result.

RELATED TAGS

repeat
string
julia
communitycreator
RELATED COURSES

View all Courses

Keep Exploring