C# – Insert a variable number of spaces into a string? (Formatting an output file) March 25, 2023 by Tarik For this you probably want myString.PadRight(totalLength, charToInsert). See String.PadRight Method (Int32) for more info.