共用方式為


Uri.CheckSchemeName(String) 方法

定義

判斷指定的配置名稱是否有效。

public:
 static bool CheckSchemeName(System::String ^ schemeName);
public static bool CheckSchemeName (string schemeName);
public static bool CheckSchemeName (string? schemeName);
static member CheckSchemeName : string -> bool
Public Shared Function CheckSchemeName (schemeName As String) As Boolean

參數

schemeName
String

要驗證的配置名稱。

傳回

Boolean

如果配置名稱有效,則為 true;否則為 false

範例

下列範例會 Uri 建立 實例,並檢查配置名稱是否有效。

Uri^ address1 = gcnew Uri( "http://www.contoso.com/index.htm#search" );
Console::WriteLine( "address 1 {0} a valid scheme name",
   Uri::CheckSchemeName( address1->Scheme ) ? (String^)" has" : " does not have" );
if ( address1->Scheme == Uri::UriSchemeHttp )
{
   Console::WriteLine( "Uri is HTTP type" );
}

Console::WriteLine( address1->HostNameType );
Uri address1 = new Uri("http://www.contoso.com/index.htm#search");
Console.WriteLine("address 1 {0} a valid scheme name",
      Uri.CheckSchemeName(address1.Scheme) ? " has" : " does not have");

if (address1.Scheme == Uri.UriSchemeHttp)
    Console.WriteLine("Uri is HTTP type");

Console.WriteLine(address1.HostNameType);
let address1 = Uri "http://www.contoso.com/index.htm#search"
printfn $"""address 1 {if Uri.CheckSchemeName address1.Scheme then " has" else " does not have"} a valid scheme name"""

if address1.Scheme = Uri.UriSchemeHttp then
    printfn "Uri is HTTP type"

printfn $"{address1.HostNameType}"
Dim address1 As New Uri("http://www.contoso.com/index.htm#search")
Console.WriteLine("address 1 {0} a valid scheme name", IIf(Uri.CheckSchemeName(address1.Scheme), " has", " does not have")) 'TODO: For performance reasons this should be changed to nested IF statements

If address1.Scheme = Uri.UriSchemeHttp Then
    Console.WriteLine("Uri is HTTP type")
End If 
Console.WriteLine(address1.HostNameType)

備註

此方法預設會根據 RFC 2396 檢查配置名稱是否有效。 如果已啟用國際資源識別碼 (IRI) 或國際化功能變數名稱 (IDN) 剖析,此方法會根據 RFC 3986 檢查配置名稱是否有效。 配置名稱的開頭必須是字母,而且只能包含字母、數位和字元 「.」、「+」 或 「-」。

如需 IRI 支援的詳細資訊,請參閱 類別的 Uri 一節。

適用於