471,350 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

How to convert a string to a GUID

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
1 3935
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.

Similar topics

3 posts views Thread by James DeClerk | last post: by
2 posts views Thread by jiangyh | last post: by
7 posts views Thread by Charles Law | last post: by
1 post views Thread by guoqi zheng | last post: by
9 posts views Thread by =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.