Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class MyClass
- {
- public static void Main()
- {
- Console.WriteLine(PadTitle("Hello",60));
- Console.WriteLine(PadTitle("",60));
- Console.WriteLine(PadTitle("World",60,'*'));
- Console.Write("Press any key to continue...");
- Console.ReadKey();
- }
- static string PadTitle(string s, int totalLength)
- {
- char paddchar = '-';
- return PadTitle(s,totalLength,paddchar);
- }
- static string PadTitle(string s, int totalLength,char paddchar)
- {
- int padlen = (totalLength - s.Length) / 2;
- int leftPad = padlen;
- int rightPad = rightPad = totalLength - (s.Length + leftPad);
- if(leftPad < 0 || rightPad < 0)
- return s;
- string msg = "".PadLeft(leftPad,paddchar);
- msg += s;
- msg += "".PadRight(rightPad, paddchar);
- return msg;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment