Currently I'm trying to print some information in the console, but I'm trying to give all results the same padding.
Here an example, you can see CurrentBuildNumber result has one /t to much. /t is only to align everything out, it could be anything else.
So, i need a "fixed" padding for the : [result]. How can i do this correctly in my code?
Thanks!
Code:
RegistryKey registryKeys = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
foreach (string registryKey in registryKeys.GetValueNames())
{
Console.WriteLine(registryKey + "\t\t: " + registryKeys.GetValue(registryKey));
}
Use string.Format() or just Console.Write() as it has support for formats
const string format = "{0,-32} :{1}";
Console.WriteLine(format, "Key", "Value")
the format value -32 means that key should take 32 positions and aligned to the left.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With