Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easiest way to build a string if i have the character and length

Tags:

string

c#

In C#, as inputs i have:

Letter: "A"
Length: 5

and i want to output:

"AAAAA"

Is there a more elegant way of doing this besides loop?

like image 783
leora Avatar asked Feb 17 '13 15:02

leora


2 Answers

You can use string constructor: new string('A', 5);

like image 119
Marcin Deptuła Avatar answered Oct 14 '22 09:10

Marcin Deptuła


You could just just the character repeating String constructor to create the String.

Console.WriteLine(new String('A', 5));
like image 23
Joachim Isaksson Avatar answered Oct 14 '22 07:10

Joachim Isaksson