Guid.TryParse メソッド

定義

オーバーロード

名前 説明
TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid)

文字のスパンを値に解析しようとします。

TryParse(ReadOnlySpan<Byte>, Guid)
TryParse(ReadOnlySpan<Char>, Guid)

GUID の表現を含む文字の指定した読み取り専用スパンを等価の Guid 構造体に変換します。

TryParse(String, Guid)

GUID の文字列形式を等価の Guid 構造体に変換します。

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Guid)

UTF-8 文字のスパンを値に解析しようとします。

TryParse(String, IFormatProvider, Guid)

文字列を値に解析しようとします。

TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid)

ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs

文字のスパンを値に解析しようとします。

public:
 static bool TryParse(ReadOnlySpan<char> s, IFormatProvider ^ provider, [Runtime::InteropServices::Out] Guid % result) = ISpanParsable<Guid>::TryParse;
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out Guid result);
static member TryParse : ReadOnlySpan<char> * IFormatProvider * Guid -> bool
Public Shared Function TryParse (s As ReadOnlySpan(Of Char), provider As IFormatProvider, ByRef result As Guid) As Boolean

パラメーター

s
ReadOnlySpan<Char>

解析する文字のスパン。

provider
IFormatProvider

sに関するカルチャ固有の書式設定情報を提供するオブジェクト。

result
Guid

このメソッドから制御が戻るときに、 sの解析に成功した結果、または失敗した場合は未定義の値が格納されます。

返品

true sが正常に解析された場合は。それ以外の場合はfalse

適用対象

TryParse(ReadOnlySpan<Byte>, Guid)

ソース:
Guid.cs
ソース:
Guid.cs
public:
 static bool TryParse(ReadOnlySpan<System::Byte> utf8Text, [Runtime::InteropServices::Out] Guid % result);
public static bool TryParse(ReadOnlySpan<byte> utf8Text, out Guid result);
static member TryParse : ReadOnlySpan<byte> * Guid -> bool
Public Shared Function TryParse (utf8Text As ReadOnlySpan(Of Byte), ByRef result As Guid) As Boolean

パラメーター

utf8Text
ReadOnlySpan<Byte>
result
Guid

返品

適用対象

TryParse(ReadOnlySpan<Char>, Guid)

ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs

GUID の表現を含む文字の指定した読み取り専用スパンを等価の Guid 構造体に変換します。

public:
 static bool TryParse(ReadOnlySpan<char> input, [Runtime::InteropServices::Out] Guid % result);
public static bool TryParse(ReadOnlySpan<char> input, out Guid result);
static member TryParse : ReadOnlySpan<char> * Guid -> bool
Public Shared Function TryParse (input As ReadOnlySpan(Of Char), ByRef result As Guid) As Boolean

パラメーター

input
ReadOnlySpan<Char>

変換する GUID を表す文字を含むスパン。

result
Guid

このメソッドから制御が戻るときに、解析された値が格納されます。 メソッドが trueを返す場合、 result には有効な Guidが含まれます。 メソッドが falseを返す場合、 resultEmptyと等しくなります。

返品

true 解析操作が成功した場合。それ以外の場合は false

適用対象

TryParse(String, Guid)

ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs

GUID の文字列形式を等価の Guid 構造体に変換します。

public:
 static bool TryParse(System::String ^ input, [Runtime::InteropServices::Out] Guid % result);
public static bool TryParse(string input, out Guid result);
public static bool TryParse(string? input, out Guid result);
static member TryParse : string * Guid -> bool
Public Shared Function TryParse (input As String, ByRef result As Guid) As Boolean

パラメーター

input
String

変換する GUID を含む文字列。

result
Guid

このメソッドから制御が戻るときに、解析された値が格納されます。 メソッドが trueを返す場合、 result には有効な Guidが含まれます。 メソッドが falseを返す場合、 resultEmptyと等しくなります。

返品

true 解析操作が成功した場合。それ以外の場合は false

次の例では、新しい GUID を作成し、"B"、"D"、および "X" 書式指定子を使用して ToString(String) メソッドを呼び出して 3 つの個別の文字列表現に変換した後、 TryParse メソッドを呼び出して文字列を Guid 値に変換します。

Guid originalGuid = Guid.NewGuid();
// Create an array of string representations of the GUID.
string[] stringGuids = { originalGuid.ToString("B"),
                         originalGuid.ToString("D"),
                         originalGuid.ToString("X") };

// Parse each string representation.
foreach (var stringGuid in stringGuids)
{
    if (Guid.TryParse(stringGuid, out var newGuid))
        Console.WriteLine($"Converted {stringGuid} to a Guid");
    else
        Console.WriteLine($"Unable to convert {stringGuid} to a Guid");
}

// The example displays output similar to the following:
//
//    Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
//    Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
//    Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid
open System

let originalGuid = Guid.NewGuid()

// Create an array of string representations of the GUID.
let stringGuids =
    [| originalGuid.ToString "B"
       originalGuid.ToString "D"
       originalGuid.ToString "X" |]

// Parse each string representation.
for stringGuid in stringGuids do
    match Guid.TryParse stringGuid with
    | true, newGuid ->
        printfn $"Converted {stringGuid} to a Guid"
    | _ ->
        printfn $"Unable to convert {stringGuid} to a Guid"

// The example displays output similar to the following:
//
//    Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
//    Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
//    Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid
Module Example
   Public Sub Main()
      Dim originalGuid As Guid = Guid.NewGuid()
      ' Create an array of string representations of the GUID.
      Dim stringGuids() As String = { originalGuid.ToString("B"),
                                      originalGuid.ToString("D"),
                                      originalGuid.ToString("X") }
      
      ' Parse each string representation.
      Dim newGuid As Guid
      For Each stringGuid In stringGuids
         If Guid.TryParse(stringGuid, newGuid) Then
            Console.WriteLine("Converted {0} to a Guid", stringGuid)
         Else
            Console.WriteLine("Unable to convert {0} to a Guid", 
                              stringGuid)
         End If     
      Next                                      
   End Sub
End Module
' The example displays the following output:
'    Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
'    Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
'    Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid

注釈

このメソッドはParseメソッドに似ていますが、解析された GUID を返す代わりに、falseが認識された形式でinputnullを返し、例外をスローしない点が異なります。 次の表に示すように、 input から先頭または末尾の空白をトリミングし、 ToString(String) および ToString(String, IFormatProvider) メソッドで認識される 5 つの形式のいずれかで文字列を変換します。

指定子 Description フォーマット
N 32 桁の数字 00000000000000000000000000000000
D ハイフンで区切られた 32 桁の数字 00000000-0000-0000-0000-000000000000
B ハイフンで区切られた 32 桁の数字 (中かっこで囲む) {00000000-0000-0000-0000-000000000000}
P かっこで囲まれたハイフンで区切られた 32 桁の数字 (00000000-0000-0000-0000-000000000000)
X 中かっこで囲まれた 4 つの 16 進値。4 番目の値は、中かっこで囲まれた 8 つの 16 進値のサブセットです {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}

こちらもご覧ください

適用対象

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Guid)

ソース:
Guid.cs
ソース:
Guid.cs

UTF-8 文字のスパンを値に解析しようとします。

public:
 static bool TryParse(ReadOnlySpan<System::Byte> utf8Text, IFormatProvider ^ provider, [Runtime::InteropServices::Out] Guid % result) = IUtf8SpanParsable<Guid>::TryParse;
public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out Guid result);
static member TryParse : ReadOnlySpan<byte> * IFormatProvider * Guid -> bool
Public Shared Function TryParse (utf8Text As ReadOnlySpan(Of Byte), provider As IFormatProvider, ByRef result As Guid) As Boolean

パラメーター

utf8Text
ReadOnlySpan<Byte>

解析する UTF-8 文字のスパン。

provider
IFormatProvider

utf8Textに関するカルチャ固有の書式設定情報を提供するオブジェクト。

result
Guid

戻り値には、 utf8Text が正常に解析された結果、または失敗した場合に未定義の値が含まれます。

返品

true utf8Textが正常に解析された場合は。それ以外の場合はfalse

適用対象

TryParse(String, IFormatProvider, Guid)

ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs
ソース:
Guid.cs

文字列を値に解析しようとします。

public:
 static bool TryParse(System::String ^ s, IFormatProvider ^ provider, [Runtime::InteropServices::Out] Guid % result) = IParsable<Guid>::TryParse;
public static bool TryParse(string? s, IFormatProvider? provider, out Guid result);
static member TryParse : string * IFormatProvider * Guid -> bool
Public Shared Function TryParse (s As String, provider As IFormatProvider, ByRef result As Guid) As Boolean

パラメーター

s
String

解析する文字列。

provider
IFormatProvider

sに関するカルチャ固有の書式設定情報を提供するオブジェクト。

result
Guid

このメソッドから制御が戻るときに、正常に s 解析された結果または失敗した場合の未定義の値が格納されます。

返品

true sが正常に解析された場合は。それ以外の場合はfalse

適用対象