Given an int n, how to return n tabs?

A

Author

I thought that this might be really simple, but I just can't figure
out how.

So, I wanna create a method that takes an int n, and the method return
n concatenated "\t"s.

i.e.,

public string GetTabs(int n)
{
if (n == 1)
{ return "\t"; }
else if (n == 2)
{ return "\t\t"; }
else if (n==3)
{ return "\t\t\t"; }
else if (n == 4)
{ return "\t\t\t\t"; }
...
...
}

I know in python, this is pretty simple, you can simple say

mystring = "\t";
myNewString = mystring * n;

And myNewString would have n "\t"s concatenated.

Is there anything similar like this in C#?

Thanks.
 
R

Registered User

I thought that this might be really simple, but I just can't figure
out how.

So, I wanna create a method that takes an int n, and the method return
n concatenated "\t"s.

i.e.,

public string GetTabs(int n)
{
return String.Empty.PadRight(n, '\t');
 
A

Andrew

I liked it Peter... true... with the habit of writing strings
day-in-and-day-out with

String thisWorld = "HelloWolrd";
....
String partialWorld = thisWorld.Substring....;

(pseudo code)

we tend to take classes like String for granted and forget to look at the
other 'less used' facilities they offer...

thanks for reminding not to forget the basics...

-Andrew
 
A

Author

I liked it Peter... true... with the habit of writing strings
day-in-and-day-out with

String thisWorld = "HelloWolrd";
...
String partialWorld = thisWorld.Substring....;

(pseudo code)

we tend to take classes like String for granted and forget to look at the
other 'less used' facilities they offer...

thanks for reminding not to forget the basics...

-Andrew

Haha, immediately after I posted this question, I realized how stupid
a question it was, so I managed to have removed it from google groups,
but the news servers were fast enough to have propagated. Thank you
guys anyway.

Quite often I notice that the attempt itself to post a question in a
news group helps resolve the question. Often times, the time I finish
writing up the question, I've already got the answer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top