Guid.ParseExact Guid.ParseExact Guid.ParseExact Guid.ParseExact Method

定義

オーバーロード

ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>) ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>) ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>) ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>)
ParseExact(String, String) ParseExact(String, String) ParseExact(String, String) ParseExact(String, String)

文字列が指定の形式であれば、GUID の文字列形式を等価の Guid 構造体に変換します。Converts the string representation of a GUID to the equivalent Guid structure, provided that the string is in the specified format.

ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>) ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>) ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>) ParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>)

public:
 static Guid ParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format);
public static Guid ParseExact (ReadOnlySpan<char> input, ReadOnlySpan<char> format);
static member ParseExact : ReadOnlySpan<char> * ReadOnlySpan<char> -> Guid
Public Shared Function ParseExact (input As ReadOnlySpan(Of Char), format As ReadOnlySpan(Of Char)) As Guid

パラメーター

format
ReadOnlySpan<Char>

戻り値

ParseExact(String, String) ParseExact(String, String) ParseExact(String, String) ParseExact(String, String)

文字列が指定の形式であれば、GUID の文字列形式を等価の Guid 構造体に変換します。Converts the string representation of a GUID to the equivalent Guid structure, provided that the string is in the specified format.

public:
 static Guid ParseExact(System::String ^ input, System::String ^ format);
public static Guid ParseExact (string input, string format);
static member ParseExact : string * string -> Guid
Public Shared Function ParseExact (input As String, format As String) As Guid

パラメーター

input
String String String String

変換対象の GUID。The GUID to convert.

format
String String String String

input を解釈するときに使用する正確な形式を示す、"N"、"D"、"B"、"P"、"X" のいずれかの指定子。One of the following specifiers that indicates the exact format to use when interpreting input: "N", "D", "B", "P", or "X".

戻り値

解析された値を格納する構造体。A structure that contains the value that was parsed.

例外

input または formatnull です。input or format is null.

inputformat で指定された形式ではありません。input is not in the format specified by format.

次の例では、ToString(String)各 1 つの GUID を表す文字列の配列を生成する サポートされている書式指定子を持つメソッド。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. 渡されますし、ParseExactメソッドで、"B"書式指定子に準拠している、文字列を正常に解析します。These are then passed to the ParseExact method, which successfully parses only the string that conforms to the "B" format specifier.

using System;

public class Example
{
   public static void Main()
   {
      // Define an array of all format specifiers.
      string[] formats = { "N", "D", "B", "P", "X" };
      Guid guid = Guid.NewGuid();
      // Create an array of valid Guid string representations.
      string[] stringGuids = new string[formats.Length];
      for (int ctr = 0; ctr < formats.Length; ctr++)
         stringGuids[ctr] = guid.ToString(formats[ctr]);

      // Parse the strings in the array using the "B" format specifier.
      foreach (var stringGuid in stringGuids) {
         try {
            Guid newGuid = Guid.ParseExact(stringGuid, "B");
            Console.WriteLine("Successfully parsed {0}", stringGuid);
         }   
         catch (ArgumentNullException) { 
            Console.WriteLine("The string to be parsed is null.");
         }   
         catch (FormatException) {
            Console.WriteLine("Bad Format: {0}", stringGuid);
         }   
      }     
   }
}
// The example displays the following output:
//    Bad Format: eb5c8c7d187a44e68afb81e854c39457
//    Bad Format: eb5c8c7d-187a-44e6-8afb-81e854c39457
//    Successfully parsed {eb5c8c7d-187a-44e6-8afb-81e854c39457}
//    Bad Format: (eb5c8c7d-187a-44e6-8afb-81e854c39457)
//    Bad Format: {0xeb5c8c7d,0x187a,0x44e6,{0x8a,0xfb,0x81,0xe8,0x54,0xc3,0x94,0x57}}
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
' The example displays the following output:
'    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}}

注釈

ParseExactメソッドで指定された形式で正確に変換する文字列が必要です、formatパラメーター、先頭と末尾の空白文字が削除された後です。The ParseExact 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. 次の表に、承認済みの書式指定子について、formatパラメーター。The following table shows the accepted format specifiers for the format parameter. 「0」に 1 桁の数字を表しますハイフン ("-")、中かっこ ("{"、"}")、およびかっこ (「(",」)") ように表示されます。"0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown.

指定子Specifier 書式設定、inputパラメーターFormat of the input parameter
NN 32 桁:32 digits:

0000000000000000000000000000000000000000000000000000000000000000
DD ハイフンで区切られた 32 桁:32 digits separated by hyphens:

00000000-0000-0000-0000-00000000000000000000-0000-0000-0000-000000000000
BB 中かっこで囲まれ、ハイフンで区切られた 32 桁:32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}
PP かっこで囲まれた、ハイフンで区切られた 32 桁:32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)(00000000-0000-0000-0000-000000000000)
xX 4 番目の値が中かっこで囲まれた 8 つの 16 進値のサブセットをかっこで囲まれた 4 つの 16 進値: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}}{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}
こちらもご覧ください

適用対象