473,395 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to know if a string is a guid

How to know if a string is a guid

thx

Nov 21 '05 #1
7 1153

ucasesoftware wrote:
How to know if a string is a guid


I suppose you culd try and construct a System.Guid from it, and see if
that throws a FormatException, but that's a little inelegant. Can't see
any other readily available method though.

--
Larry Lard
Replies to group please

Nov 21 '05 #2
"ucasesoftware" <uc***********@hotmail.fr> schrieb:
How to know if a string is a guid


For example:

\\\
Try
Dim g As New Guid(<string>)
Catch ex As FormatException
...
End Try
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #3
Hi,

I would use an regular expression.

Dim regGuid As New
Regex("^\{?[a-fA-F\d]{8}-([a-fA-F\d]{4}-){3}[a-fA-F\d]{12}\}?$")

Dim strTest As String = Guid.NewGuid.ToString
Trace.WriteLine(regGuid.IsMatch(strTest))
Trace.WriteLine(regGuid.IsMatch("No way"))
Ken
------------------------
"ucasesoftware" <uc***********@hotmail.fr> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
How to know if a string is a guid

thx

Nov 21 '05 #4
ucasesoftware,
I would normally use the method Herfried suggests:

Try
Dim g As New Guid(<string>)
Catch ex As FormatException
...
End Try

I was going to suggest TryParse with VB 2005, however I don't see it listed
for Guid, just the "numeric" types (Integer, Long, Single, Double, Decimal,
DateTime...) possibly because Guid doesn't have a Parse function...

If I considered the RegEx approach as Ken suggests, I would be certain to
take into account all 5 formats that a GUID could be in:

http://msdn.microsoft.com/library/de...ctorTopic2.asp

Ergo I suspect the Try/Catch would be "easier" in the long run, although the
RegEx approach might be "Better" for dialog boxes...

--
Hope this helps
Jay
T.S. Bradley - http://www.tsbradley.net
"ucasesoftware" <uc***********@hotmail.fr> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
| How to know if a string is a guid
|
| thx
|
Nov 21 '05 #5
Jay,
I would normally use the method Herfried suggests:

Just before somebody gets wrong idea from you, from what I am sure is not
your intention.

In my opinion Larry and Hefried, they posted in my opinion at about the same
time almost the same solution.

Cor
Nov 21 '05 #6
Cor,
| Just before somebody gets wrong idea from you, from what I am sure is not
| your intention.
Huh?

| In my opinion Larry and Hefried, they posted in my opinion at about the
same
| time almost the same solution.
Yes Larry & Herfried gave the "same" technique, however only Herfried gave
sample code. I was giving Herfried credit for using his code.

--
Hope this helps
Jay
T.S. Bradley - http://www.tsbradley.net
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
| Jay,
|
| > I would normally use the method Herfried suggests:
| >
| Just before somebody gets wrong idea from you, from what I am sure is not
| your intention.
|
| In my opinion Larry and Hefried, they posted in my opinion at about the
same
| time almost the same solution.
|
| Cor
|
|
Nov 21 '05 #7
Thx for those answers...

As you are all very good, can you look at this thread :
http://groups.google.fr/group/micros...61763585f458b2

i have no answer and it's very important for me :)

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ME | last post by:
I am developing a kind of plugin framework that I can use for several applications I want to make. In order to identify individual plugins I am currently doing something like the code below...
5
by: jan axelson | last post by:
My application is using RegisterDeviceNotification() to detect attachment and removal of a USB HID-class device. The form is receiving WM_DEVICECHANGE messages with wParam set to...
1
by: Wolf | last post by:
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...
1
by: Steph | last post by:
hello, i ve tries to convert a generic into a string for use string.join. no problems with arraylist : ArrayList al = new ArrayList(); al.Add("J1"); al.Add("J2"); al.Add("J3");...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.