edance
edance

Reputation: 620

Repeat a string n times in elixir

I need to make a string of a defined length. In ruby, I would use:

str = 'a' * 5

How do I accomplish the same thing in elixir?

Upvotes: 19

Views: 8045

Answers (1)

Dogbert
Dogbert

Reputation: 222188

You can use String.duplicate/2:

iex(1)> str = String.duplicate("a", 5)
"aaaaa"

Upvotes: 45

Related Questions