Guid::Parse Method (String^)
Converts the string representation of a GUID to the equivalent Guid structure.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- input
-
Type:
System::String^
The string to convert.
| Exception | Condition |
|---|---|
| ArgumentNullException | input is null. |
| FormatException | input is not in a recognized format. |
The Parse method trims any leading or trailing white space from input and converts the string representation of a GUID to a Guid value. This method can convert strings in any of the five formats produced by the ToString(String^) and ToString(String^, IFormatProvider^) methods, as shown in the following table.
Specifier | Description | Format |
|---|---|---|
N | 32 digits | 00000000000000000000000000000000 |
D | 32 digits separated by hyphens | 00000000-0000-0000-0000-000000000000 |
B | 32 digits separated by hyphens, enclosed in braces | {00000000-0000-0000-0000-000000000000} |
P | 32 digits separated by hyphens, enclosed in parentheses | (00000000-0000-0000-0000-000000000000) |
X | Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces | {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} |
The method throws a FormatException if it is unable to successfully parse the string. Here are some of the reasons why this might occur include:
input contains characters that are not part of the hexadecimal character set.
input has too many or too few numeric characters.
input has too many or too few of the non-numeric characters appropriate for a particular format.
input is not in one of the formats recognized by the ToString method and listed in the previous table.
Use the TryParse method to catch any unsuccessful parse operations without having to handle an exception.
The following example creates a new GUID, converts it to three separate string representations by calling the ToString(String^) method with the "B", "D", and "X" format specifiers, and then calls the Parse method to convert the strings back to Guid values.
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 7.1
Windows Phone
Available since 8.1