-2

I want to print many line. Each line is a string plus white spaces plus a second string.

I want the second part string in each line aligning. So I use PadRight; but it is not working well.

Code:

void Main()
{
   var str ="Hellooooo".PadRight(50)+"Test";
   str += (Environment.NewLine+"World").PadRight(50)+"Test";
   str+= (Environment.NewLine+"Hello Worldoooooooo").PadRight(50)+"Test";
   Console.WriteLine(str);
}

The output likes 1

You can see the three "Test" are not aligning vertically.

Julian
  • 33,915
  • 22
  • 119
  • 174
Bigeyes
  • 1,508
  • 2
  • 23
  • 42
  • Usually its better to use a more table friendly control. Does it really need to be aligned using whitespaces? If it is not Console's output. The screenshot looks different. – CSharpie Apr 19 '17 at 20:12

1 Answers1

0

If you like to align text white spaces, then you need a mono space font (every char same width), like courier new.

Also Environment.NewLine is in the second and third string, but not the first.

When fixing the Environment.NewLine and using a monospace font, this works:

public static void Main()
{
    var str ="Hellooooo".PadRight(50)+"Test";
    str += Environment.NewLine + ("World").PadRight(50)+"Test";
    str += Environment.NewLine + ("Hello Worldoooooooo").PadRight(50)+"Test";
    Console.WriteLine(str);
}

result

See live demo

Julian
  • 33,915
  • 22
  • 119
  • 174