How to convert a string to a GUID

  • Thread starter Thread starter Wolf
  • Start date Start date
W

Wolf

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
 
Wolf said:
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
 
Back
Top