Guid.TryParseExact 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| TryParseExact(String, String, Guid) |
문자열이 지정된 형식인 경우 GUID의 문자열 표현을 해당하는 Guid 구조체로 변환합니다. |
| TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, Guid) |
문자열이 지정된 형식인 경우 GUID를 나타내는 문자 범위를 해당하는 Guid 구조체로 변환합니다. |
TryParseExact(String, String, Guid)
- Source:
- Guid.cs
- Source:
- Guid.cs
- Source:
- Guid.cs
- Source:
- Guid.cs
- Source:
- Guid.cs
문자열이 지정된 형식인 경우 GUID의 문자열 표현을 해당하는 Guid 구조체로 변환합니다.
public:
static bool TryParseExact(System::String ^ input, System::String ^ format, [Runtime::InteropServices::Out] Guid % result);
public static bool TryParseExact(string input, string format, out Guid result);
public static bool TryParseExact(string? input, string? format, out Guid result);
static member TryParseExact : string * string * Guid -> bool
Public Shared Function TryParseExact (input As String, format As String, ByRef result As Guid) As Boolean
매개 변수
- input
- String
변환할 GUID입니다.
- format
- String
해석 input할 때 사용할 정확한 형식을 나타내는 다음 지정자 중 하나입니다. "N", "D", "B", "P" 또는 "X".
- result
- Guid
이 메서드가 반환될 때 구문 분석된 값을 포함합니다. 메서드가 반환 trueresult 되면 유효한 Guid. 메서드가 반환 falseresult 되면 같아 줍니다.Empty
반품
true구문 분석 작업이 성공하면 이고, 그렇지 않으면 . false
예제
다음 예제에서는 지원되는 각 형식 지정자를 사용하여 메서드를 호출 ToString(String) 하여 단일 GUID를 나타내는 문자열 배열을 생성합니다. 그런 다음 메서드에 TryParseExact 전달되어 "B" 형식 지정자를 따르는 문자열을 성공적으로 구문 분석합니다.
// 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.
var 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)
{
if (Guid.TryParseExact(stringGuid, "B", out var newGuid))
Console.WriteLine($"Successfully parsed {stringGuid}");
else
Console.WriteLine($"Unable to parse '{stringGuid}'");
}
// The example displays output similar to the following:
//
// Unable to parse 'c0fb150f6bf344df984a3a0611ae5e4a'
// Unable to parse 'c0fb150f-6bf3-44df-984a-3a0611ae5e4a'
// Successfully parsed {c0fb150f-6bf3-44df-984a-3a0611ae5e4a}
// Unable to parse '(c0fb150f-6bf3-44df-984a-3a0611ae5e4a)'
// Unable to parse '{0xc0fb150f,0x6bf3,0x44df,{0x98,0x4a,0x3a,0x06,0x11,0xae,0x5e,0x4a}}'
open System
// Define an array of all format specifiers.
let formats = [| "N"; "D"; "B"; "P"; "X" |]
let guid = Guid.NewGuid()
// Create an array of valid Guid string representations.
let stringGuids =
Array.map guid.ToString formats
// Parse the strings in the array using the "B" format specifier.
for stringGuid in stringGuids do
match Guid.TryParseExact(stringGuid, "B") with
| true, newGuid ->
printfn $"Successfully parsed {stringGuid}"
| _ ->
printfn $"Unable to parse '{stringGuid}'"
// The example displays output similar to the following:
//
// Unable to parse 'c0fb150f6bf344df984a3a0611ae5e4a'
// Unable to parse 'c0fb150f-6bf3-44df-984a-3a0611ae5e4a'
// Successfully parsed {c0fb150f-6bf3-44df-984a-3a0611ae5e4a}
// Unable to parse '(c0fb150f-6bf3-44df-984a-3a0611ae5e4a)'
// Unable to parse '{0xc0fb150f,0x6bf3,0x44df,{0x98,0x4a,0x3a,0x06,0x11,0xae,0x5e,0x4a}}'
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
' Try to parse the strings in the array using the "B" format specifier.
For Each stringGuid In stringGuids
Dim newGuid As Guid
If Guid.TryParseExact(stringGuid, "B", newGuid) Then
Console.WriteLine("Successfully parsed {0}", stringGuid)
Else
Console.WriteLine("Unable to parse '{0}'", stringGuid)
End If
Next
End Sub
End Module
' The example displays the following output:
' Unable to parse 'c0fb150f6bf344df984a3a0611ae5e4a'
' Unable to parse 'c0fb150f-6bf3-44df-984a-3a0611ae5e4a'
' Successfully parsed {c0fb150f-6bf3-44df-984a-3a0611ae5e4a}
' Unable to parse '(c0fb150f-6bf3-44df-984a-3a0611ae5e4a)'
' Unable to parse '{0xc0fb150f,0x6bf3,0x44df,{0x98,0x4a,0x3a,0x06,0x11,0xae,0x5e,0x4a}}'
설명
이 메서드를 사용하려면 선행 및 후행 공백 문자가 제거된 후 문자열이 매개 변수에 format 지정된 형식으로 정확하게 변환되어야 합니다. 지정한 형식false이 아닌 경우 inputnull 반환 format 되며 예외를 throw하지 않습니다.
다음 표에서는 매개 변수에 허용되는 format 형식 지정자를 보여줍니다. "0"은 숫자를 나타냅니다. 하이픈("-"), 중괄호("{", "}") 및 괄호("(", ")")가 표시된 것처럼 표시됩니다.
| 지정자 | 매개 변수의 input 형식 |
|---|---|
| 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진수 값입니다. 여기서 네 번째 값은 중괄호로 묶인 8개의 16진수 값의 하위 집합입니다. {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} |
추가 정보
적용 대상
TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, Guid)
- Source:
- Guid.cs
- Source:
- Guid.cs
- Source:
- Guid.cs
- Source:
- Guid.cs
- Source:
- Guid.cs
문자열이 지정된 형식인 경우 GUID를 나타내는 문자 범위를 해당하는 Guid 구조체로 변환합니다.
public:
static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, [Runtime::InteropServices::Out] Guid % result);
public static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, out Guid result);
static member TryParseExact : ReadOnlySpan<char> * ReadOnlySpan<char> * Guid -> bool
Public Shared Function TryParseExact (input As ReadOnlySpan(Of Char), format As ReadOnlySpan(Of Char), ByRef result As Guid) As Boolean
매개 변수
- input
- ReadOnlySpan<Char>
변환할 GUID를 나타내는 문자를 포함하는 읽기 전용 범위입니다.
- format
- ReadOnlySpan<Char>
해석할 때 input사용할 정확한 형식을 나타내는 다음 지정자 중 하나를 나타내는 문자를 포함하는 읽기 전용 범위입니다. "N", "D", "B", "P" 또는 "X".
- result
- Guid
이 메서드가 반환될 때 구문 분석된 값을 포함합니다. 메서드가 반환 trueresult 되면 유효한 Guid. 메서드가 반환 falseresult 되면 같아 줍니다.Empty
반품
true구문 분석 작업이 성공하면 이고, 그렇지 않으면 . false