fork download
  1. using System;
  2. using static System.Console;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. Write($"|{("Hello World".PadBoth(42))}|");
  7. }
  8. }
  9.  
  10. namespace System {
  11. public static class StringExt {
  12. public static string PadBoth(this string str, int length, char character = ' ') => str.PadLeft((length - str.Length) / 2 + str.Length, character).PadRight(length, character);
  13. }
  14. }
  15.  
  16. //https://pt.stackoverflow.com/q/41755/101
Success #stdin #stdout 0.02s 15848KB
stdin
Standard input is empty
stdout
|               Hello World                |