本文整理匯總了VB.NET中System.Guid.ParseExact方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Guid.ParseExact方法的具體用法?VB.NET Guid.ParseExact怎麽用?VB.NET Guid.ParseExact使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Guid
的用法示例。
在下文中一共展示了Guid.ParseExact方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
Module Example
Public Sub Main()
' Define an array of all format specifiers.
Dim formats() As String = { "N", "D", "B", "P", "X" }
Dim guid As Guid = Guid.NewGuid()
' Create an array of valid Guid string representations.
Dim stringGuids(formats.Length - 1) As String
For ctr As Integer = 0 To formats.Length - 1
stringGuids(ctr) = guid.ToString(formats(ctr))
Next
' Parse the strings in the array using the "B" format specifier.
For Each stringGuid In stringGuids
Try
Dim newGuid As Guid = Guid.ParseExact(stringGuid, "B")
Console.WriteLine("Successfully parsed {0}", stringGuid)
Catch e As ArgumentNullException
Console.WriteLine("The string to be parsed is null.")
Catch e As FormatException
Console.WriteLine("Bad Format: {0}", stringGuid)
End Try
Next
End Sub
End Module
輸出:
Bad Format: 3351d3f0006747089ff928b5179b2051 Bad Format: 3351d3f0-0067-4708-9ff9-28b5179b2051 Successfully parsed {3351d3f0-0067-4708-9ff9-28b5179b2051} Bad Format: (3351d3f0-0067-4708-9ff9-28b5179b2051) Bad Format: {0x3351d3f0,0x0067,0x4708,{0x9f,0xf9,0x28,0xb5,0x17,0x9b,0x20,0x51}}