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 检查方案名称是否有效。 如果启用了国际资源标识符 (IIS) 或国际化域名 (IDN) 分析,此方法会根据 RFC 3986 检查方案名称是否有效。 方案名称必须以字母开头,并且只能包含字母、数字和字符“.”、“+”或“-”。

有关 IRI 支持的详细信息,请参阅类的 Uri “备注”部分。

适用于