eWorld.UI - Matt Hawley

Ramblings of Matt

Erik Porter Saves Time

April 27, 2004 00:06 by matthaw

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.

Categories: .NET
Actions: E-mail | Permalink | Comments (4) | Comment RSSRSS comment feed


April 27. 2004 00:10

Glad to help, Matt!  Thanks for pointing out "B"  Smile  Now when I forget how to do it, I can look through my blog, click on the trackback and there your entry will be!  Laughing


April 27. 2004 02:43

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

"N" 32 digits:


"D" 32 digits separated by hyphens:


"P" 32 digits separated by hyphens, enclosed in parentheses:


Wayne Allen

April 27. 2004 06:38

Long live censorship Smile


April 27. 2004 15:05

If all you wanted in the first attempt was to put curly brackets around the guid, you should have done this {{{0}}}.

As the documentation states:

'The leading and trailing brace characters, '{' and '}', are required. To specify a single literal brace character in format, specify two leading or trailing brace characters; that is, "{{" or "}}".'


Oskar Austegard

Comments are closed

Copyright © 2000 - 2024 , Excentrics World