By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,360 Members | 2,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,360 IT Pros & Developers. It's quick & easy.

How to convert a string to a GUID

P: n/a
Hi

I am trying to set a property(PartyHomeAddressID) = to a guid in a ini
file.
But everytime when the ini file has an empty guid it breaks with an
error tellin me a guid is 32 char long with 4 dashes.
client.PartyHomeAddressID = new Guid(contact.Substring(1542,
36).Trim());

If its not Empty GUID, it doesnt break.

Is the reason maybe because I am specifying new Guid( around a empty
guid?
If this is the case, how do I convert it to read a GUID

Thanks a million in advance

Jan 26 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Wolf wrote:
I am trying to set a property(PartyHomeAddressID) = to a guid in a ini
file.
But everytime when the ini file has an empty guid it breaks with an
error tellin me a guid is 32 char long with 4 dashes.

client.PartyHomeAddressID = new Guid(contact.Substring(1542,
36).Trim());

If its not Empty GUID, it doesnt break.

Is the reason maybe because I am specifying new Guid( around a empty
guid?
If this is the case, how do I convert it to read a GUID


The constructor Guid(string) assumes that you're passing it a valid
string representation of a Guid. If you're not, it's (not unreasonably)
complaining.

What do you *want* it to do if your ini file has an empty guid? Should
it create a new Guid, should it use an "all zero" Guid? Your code needs
to decide this - check whether or not a guid has been supplied in the
ini file, use it if it has, and take appropriate action if not.

Jon

Jan 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.