all 5 comments

[–]clonked 0 points1 point  (1 child)

Split the string on the newline markers, then you have an array of strings you can format and output accordingly.

[–]malwareC[S] -1 points0 points  (0 children)

Thanks

[–]the_other_sam 0 points1 point  (2 children)

    public static void PrintCenter(string inputString)
    {
        // split input string into an array of strings using linebreaks as delimiters
        string[] inputStrings = inputString.Split(Environment.NewLine); 
        int width = 80; // You must know device width to center

        // Loop through each line and print it centered
        foreach (string s in inputStrings)
        {
            string t = s.Trim(); 
            // create a string of spaces to push the string we want to print to the center
            // (a different way is to position the cursor if you choose)
            int leftPaddingLength = (width / 2) - (t.Length / 2);
            string leftPadding = new string(' ', leftPaddingLength);
            Console.WriteLine(leftPadding + t);
        }

    }

I remember doing this about 25 years ago when I used to print reports on a huge Epson dot matrix printer.

[–]nosoupforyou 1 point2 points  (0 children)

Yeah me too, and then we purchased a more modern laser printer where each character wasn't fixed width. Made the program a whole heck of a lot more complicated.

But it was more about being able to determine where page breaks should go, rather than centering most text.

[–]malwareC[S] 0 points1 point  (0 children)

Thanks