Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
TryParseExact Method

Guid::TryParseExact Method

Converts the string representation of a GUID to the equivalent Guid structure, provided that the string is in the specified format.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public:
static bool TryParseExact(
	String^ input, 
	String^ format, 
	[OutAttribute] Guid% result
)

Parameters

input
Type: System::String

The GUID to convert.

format
Type: System::String

One of the following specifiers that indicates the exact format to use when interpreting input: "N", "D", "B", "P", or "X".

result
Type: System::Guid%

The structure that will contain the parsed value. If the method returns true, result contains a valid Guid. If the method returns false, result equals Guid::Empty.

Return Value

Type: System::Boolean
true if the parse operation was successful; otherwise, false.

This method requires the string to convert to be exactly in the format specified by the format parameter, after leading and trailing white-space characters are removed. It returns false if input is nullptr or is not in the format specified by format, and doesn't throw an exception.

The following table shows the accepted format specifiers for the format parameter. "0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown.

Specifier

Format of the input parameter

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 following example calls the ToString(String) method with each of the supported format specifiers to generate an array of strings that represent a single GUID. These are then passed to the TryParseExact method, which successfully parses the string that conforms to the "B" format specifier.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft