Uri.CheckSchemeName(String) Uri.CheckSchemeName(String) Uri.CheckSchemeName(String) Uri.CheckSchemeName(String) Method

定义

确定指定的方案名是否有效。Determines whether the specified scheme name is valid.

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

参数

schemeName
String String String String

要验证的方案名。The scheme name to validate.

返回

一个 Boolean 值。如果方案名有效,则该值为 true;否则为 falseA Boolean value that is true if the scheme name is valid; otherwise, false.

示例

下面的示例创建一个Uri实例, 并检查方案名是否有效。The following example creates a Uri instance and checks whether the scheme name is valid.

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);
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 检查方案名称的有效性。This method checks the scheme name for validity according to RFC 2396 by default. 如果启用了国际资源标识符 (IRIs) 或国际化域名 (IDN) 分析, 此方法将根据 RFC 3986 检查方案名称的有效性。If International Resource Identifiers (IRIs) or Internationalized Domain Name (IDN) parsing is enabled, this method checks the scheme name for validity according to RFC 3986. 方案名称必须以字母开头, 并且必须仅包含字母、数字和字符 "."、"+" 或 "-"。The scheme name must begin with a letter and must contain only letters, digits, and the characters ".", "+", or "-".

有关 IRI 支持的详细信息, 请参阅Uri类的 "备注" 部分。For more information on IRI support, see the Remarks section for the Uri class.

适用于