I'm trying to make a simple tab space between words, using a dynamic ammount. How would I do this?
Simply like this:
string p1 = keysC[pos]+"="+valsC[pos];
int tabs = (60 - p1.Length) / 4;
wr.WriteLine(p1 + ("\t" * tabs) +"//"+comsC[pos]);
I'm trying to make a simple tab space between words, using a dynamic ammount. How would I do this?
Simply like this:
string p1 = keysC[pos]+"="+valsC[pos];
int tabs = (60 - p1.Length) / 4;
wr.WriteLine(p1 + ("\t" * tabs) +"//"+comsC[pos]);
The String contructor has an overload for that.
string p1 = keysC[pos]+"="+valsC[pos];
int tabs = (60 - p1.Length) / 4;
wr.WriteLine(p1 + new string('\t', tabs) +"//"+comsC[pos]);
Note that the first argument of the constructor is a char and not a string.
Sounds like just need to write a function that repeats the same string N number of times
static string RepeatString(string source, int times) {
var builder = new StringBuilder(source.Length * times);
for (int i = 0; i < times; i++) {
builder.Append(source);
}
return builder.ToString();
}
Note that if you only care about repeating a char like \t then use @Vache's answer of new string(theChar, theCount)
String.Join(null, Enumerable.Repeat(source, times));