Guid.Parse 메서드

정의

오버로드

Parse(String, IFormatProvider)

문자열을 값으로 구문 분석합니다.

Parse(ReadOnlySpan<Char>, IFormatProvider)

문자 범위를 값으로 구문 분석합니다.

Parse(ReadOnlySpan<Char>)

GUID를 나타내는 읽기 전용 문자 범위를 해당하는 Guid 구조체로 변환합니다.

Parse(String)

GUID의 문자열 표현을 해당 Guid 구조체로 변환합니다.

Parse(String, IFormatProvider)

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

문자열을 값으로 구문 분석합니다.

public:
 static Guid Parse(System::String ^ s, IFormatProvider ^ provider) = IParsable<Guid>::Parse;
public static Guid Parse (string s, IFormatProvider? provider);
static member Parse : string * IFormatProvider -> Guid
Public Shared Function Parse (s As String, provider As IFormatProvider) As Guid

매개 변수

s
String

구문 분석할 문자열입니다.

provider
IFormatProvider

s에 대한 문화권별 서식 정보를 제공하는 개체입니다.

반환

구문 분석의 결과입니다 s.

구현

적용 대상

Parse(ReadOnlySpan<Char>, IFormatProvider)

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

문자 범위를 값으로 구문 분석합니다.

public:
 static Guid Parse(ReadOnlySpan<char> s, IFormatProvider ^ provider) = ISpanParsable<Guid>::Parse;
public static Guid Parse (ReadOnlySpan<char> s, IFormatProvider? provider);
static member Parse : ReadOnlySpan<char> * IFormatProvider -> Guid
Public Shared Function Parse (s As ReadOnlySpan(Of Char), provider As IFormatProvider) As Guid

매개 변수

s
ReadOnlySpan<Char>

구문 분석할 문자의 범위입니다.

provider
IFormatProvider

s에 대한 문화권별 서식 정보를 제공하는 개체입니다.

반환

구문 분석의 결과입니다 s.

구현

적용 대상

Parse(ReadOnlySpan<Char>)

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

GUID를 나타내는 읽기 전용 문자 범위를 해당하는 Guid 구조체로 변환합니다.

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

매개 변수

input
ReadOnlySpan<Char>

GUID를 나타내는 바이트를 포함하는 읽기 전용 범위입니다.

반환

구문 분석된 값을 포함하는 구조체입니다.

예외

input의 형식을 인식할 수 없는 경우

또는

트리밍 후 읽기 전용 문자 범위의 길이는 0입니다.

설명

메서드는 Parse 에서 선행 또는 후행 공백 문자를 input 잘라내고 의 나머지 문자를 input 값으로 Guid 변환합니다. 이 메서드는 다음 표와 같이 메서드에서 생성된 ToString 5가지 형식 중 하나라도 나타내는 문자 범위를 변환할 수 있습니다.

지정자 설명 서식
N 326진수 00000000000000000000000000000000
D 하이픈으로 구분된 32자리 16진수 00000000-0000-0000-0000-000000000000
B 하이픈으로 구분된 32개의 16진수 숫자로 중괄호로 묶습니다. {00000000-0000-0000-0000-000000000000}
P 괄호로 묶은 하이픈으로 구분된 326진수 숫자 (00000000-0000-0000-0000-000000000000)
X 중괄호로 묶인 4개의 16진수 값입니다. 여기서 네 번째 값은 중괄호로 묶인 8개의 16진수 값의 하위 집합입니다. {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}

메서드는 문자열을 FormatException 성공적으로 구문 분석할 수 없는 경우 을 throw합니다. 이러한 상황이 발생할 수 있는 몇 가지 이유는 다음과 같습니다.

  • input 에는 16진수 문자 집합에 속하지 않는 문자가 포함되어 있습니다.

  • input 문자가 너무 많거나 너무 적습니다.

  • input 가 메서드에서 인식하고 ToString 이전 표에 나열된 형식 중 하나가 아닙니다.

메서드를 TryParse 사용하여 예외를 처리하지 않고도 실패한 구문 분석 작업을 catch합니다.

적용 대상

Parse(String)

Source:
Guid.cs
Source:
Guid.cs
Source:
Guid.cs

GUID의 문자열 표현을 해당 Guid 구조체로 변환합니다.

public:
 static Guid Parse(System::String ^ input);
public static Guid Parse (string input);
static member Parse : string -> Guid
Public Shared Function Parse (input As String) As Guid

매개 변수

input
String

변환할 문자열입니다.

반환

구문 분석된 값을 포함하는 구조체입니다.

예외

input이(가) null인 경우

input의 형식을 인식할 수 없는 경우

예제

다음 예제에서는 새 GUID를 만들고 , "B", "D" 및 "X" 형식 지정자를 사용하여 메서드를 호출 ToString(String) 하여 세 개의 개별 문자열 표현으로 변환한 다음 메서드를 호출 Parse 하여 문자열을 다시 값으로 Guid 변환합니다.

var 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)
{
    try
    {
        Guid newGuid = Guid.Parse(stringGuid);
        Console.WriteLine($"Converted {stringGuid} to a Guid");
    }
    catch (ArgumentNullException)
    {
        Console.WriteLine("The string to be parsed is null.");
    }
    catch (FormatException)
    {
        Console.WriteLine($"Bad format: {stringGuid}");
    }
}

// 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
    try
        let newGuid = Guid.Parse stringGuid
        printfn $"Converted {stringGuid} to a Guid"
    with
    | :? ArgumentNullException ->
        printfn "The string to be parsed is null."
    | :? FormatException ->
        printfn $"Bad format: {stringGuid}"

// 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.
      For Each stringGuid In stringGuids
         Try 
            Dim newGuid As Guid = Guid.Parse(stringGuid) 
            Console.WriteLine("Converted {0} to a Guid", 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:
'    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 에서 선행 또는 후행 공백 input 을 잘라내고 GUID의 문자열 표현을 값으로 Guid 변환합니다. 이 메서드는 다음 표와 같이 및 ToString(String, IFormatProvider) 메서드에서 생성된 ToString(String) 5가지 형식 중 하나로 문자열을 변환할 수 있습니다.

지정자 설명 서식
N 326진수 00000000000000000000000000000000
D 하이픈으로 구분된 32자리 16진수 00000000-0000-0000-0000-000000000000
B 하이픈으로 구분된 32개의 16진수 숫자로 중괄호로 묶습니다. {00000000-0000-0000-0000-000000000000}
P 괄호로 묶은 하이픈으로 구분된 326진수 숫자 (00000000-0000-0000-0000-000000000000)
X 중괄호로 묶인 4개의 16진수 값입니다. 여기서 네 번째 값은 중괄호로 묶인 8개의 16진수 값의 하위 집합입니다. {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}

메서드는 문자열을 FormatException 성공적으로 구문 분석할 수 없는 경우 을 throw합니다. 이러한 상황이 발생할 수 있는 몇 가지 이유는 다음과 같습니다.

  • input 에는 16진수 문자 집합에 속하지 않는 문자가 포함되어 있습니다.

  • input 문자가 너무 많거나 너무 적습니다.

  • input 가 메서드에서 인식하고 ToString 이전 표에 나열된 형식 중 하나가 아닙니다.

메서드를 TryParse 사용하여 예외를 처리하지 않고도 실패한 구문 분석 작업을 catch합니다.

추가 정보

적용 대상