Skip to content

Instantly share code, notes, and snippets.

@dannylloyd
Created June 24, 2020 20:53
Show Gist options
  • Save dannylloyd/223fbfacc1ed3e3fcbf874cb512f2d8c to your computer and use it in GitHub Desktop.
Save dannylloyd/223fbfacc1ed3e3fcbf874cb512f2d8c to your computer and use it in GitHub Desktop.
Padding with string instead of char literal
public static class Extensions
{
public static string PadRight(this string input, int totalWidth, string paddingString){
var rep = string.Concat(Enumerable.Repeat(paddingString, totalWidth-input.Length));
return (input + rep);
}
public static string PadLeft(this string input, int totalWidth, string paddingString){
var rep = string.Concat(Enumerable.Repeat(paddingString, totalWidth-input.Length));
return (rep + input);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment