Erik Porter Saves Time

Sounds like a nice headline for a newspaper, huh. I thought so too. Anyway, to the point of this post, I was struggling with formatting a Guid to the "registry" way of viewing it, you know - 32 digits separated by hyphens with curly brackets around it.

1st attempt - Code: String.Format("{{0}}", myguid)
1st attempt - Result: "{0}" <-- Which is very weird indeed, maybe a bug?

And then whammo! It dawned on me. I had just recently seen this post by Erik Porter...but I really didn't remember the meat of what Guid.ToString("N") meant (I hadn't pulled the post up yet).

2nd attempt - Code: myguid.ToString("N")
2nd attempt - Result: 23452345234235235242 (I know this isn't 32 digits)

Err - so that wasn't quite what I expected, but then again, I really wasn't sure what that "N" did. Ohh, so why not just open up the SDK docs, Microsoft had to have put something in there for the format I wanted. Ahh, sure enough, theres a "B" that gets what I want.

3rd attempt - Code myguid.ToString("B")
3rd attempt - Result: {2315123-2314-....}

Wahoo, Success! Man am I glad Erik saw & blogged about this the other week. Time saved, about 15 - 20 minutes wondering why the heck I'm getting {0} for the format of {{0}}. Thanks Erik!

PS - Whoever said blogs weren't a good source of information.

3 Comments

  • Glad to help, Matt! Thanks for pointing out &quot;B&quot; :) Now when I forget how to do it, I can look through my blog, click on the trackback and there your entry will be! :D

  • Don't forget our other friends N, D &amp; P! I had to figure this out the hard way when dealing with the MSCRM SDK.



    &quot;N&quot; 32 digits:

    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



    &quot;D&quot; 32 digits separated by hyphens:

    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx





    &quot;P&quot; 32 digits separated by hyphens, enclosed in parentheses:

    (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)



  • Long live censorship :)

Comments have been disabled for this content.