Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# Formatting a string with string.Format("00-00-00")

I am attempting convert this string "123456" to "12-34-56".
I try to use this code but it doesn’t seem to work correctly

string.Format("123456", "00-00-00");

Can anyone help me find a suitable pattern? Thanks for any help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use below

string.Format("{0:##-##-##}", 123456);

If number is represented as string the convert to int

string.Format("{0:##-##-##}", Convert.ToInt32("123456"));

The above will print the output as

12-34-56

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading