|
|
|
date: Tue, 8 Jul 2008 08:06:06 -0700,
group: microsoft.public.dotnet.languages.csharp
back
Re: repeat character
"raulavi" wrote in message
news:AE262A06-16D6-405B-82AC-281267EE3E82@microsoft.com...
> Hi:
> vs2008 c#
> Having a string myvar = "*";
>
> I need to repeat this myvar 100 times when is used at run time...
>
> string myline = myvar + myvar+ myvar....(100 times)
>
> What the easiest way to acomplish this.
>
> am trying to avoid the for loop
>
Multiple answers and so far, all can be correct, so I thought I'd throw in
another case...
If the string or "character" is just a space (which in your example, it
showed an asterisk [*], but I'm throwing in a space just for show):
string myvar = string.Empty.PadRight(100);
- OR - a normal character (note, char is not string):
string myvar = string.Empty.PadRight(100, '*');
Personally, I would use the constructor for string that takes a character
and count (already posted by someone else, but duplicated here):
string myvar = new string('*', 100);
There ;) HTH,
Mythran
date: Tue, 8 Jul 2008 09:21:25 -0700
author: Mythran am
|
|