المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : String format for MAC-address



C# Programming
03-25-2011, 11:00 AM
I would like to convert a string representing a MAC-address in one format to an other format. I thought I could use the String.Format() method to do this, but I don't get what I want.

I'm looking for this sequence flow:

Soruce: 00204A846187
Result: 00-20-4A-84-61-87

My code:
string mac1 = "00204A846187";
string mac2 = String.Format("{0:##-##-##-##-##-##}", mac1);
Console.WriteLine(mac1 + " converted to: " + mac2); When I run that I don't get what I want. mac2 is the same as mac1 variable... http://www.barakasoft.com/script/Forums/Images/smiley_doh.gif
I hope I missed something because I don't want to loop through every other charecter and append "-" manually.

Any suggestions?