HtmlTextWriter.EncodeUrl(String) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した URL 内のスペースを文字列 "%20" に変換することで、最小限の URL エンコードを実行します。
protected:
System::String ^ EncodeUrl(System::String ^ url);
protected string EncodeUrl(string url);
member this.EncodeUrl : string -> string
Protected Function EncodeUrl (url As String) As String
パラメーター
- url
- String
エンコードする URL を含む文字列。
返品
エンコードされた URL を含む文字列。
例
次のコード例では、 EncodeUrl メソッドを呼び出して、 AddAttribute メソッド呼び出しでパラメーターとして渡される URL 内のスペースを変換する方法を示します。
// If an <anchor> element is rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute
// and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if ( TagKey == HtmlTextWriterTag::A )
{
if ( !IsAttributeDefined( HtmlTextWriterAttribute::Href ) )
{
AddAttribute( "href", EncodeUrl( "http://www.cohowinery.com" ) );
}
}
// If an <anchor> element is rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute
// and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if (TagKey == HtmlTextWriterTag.A)
{
if (!IsAttributeDefined(HtmlTextWriterAttribute.Href))
{
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"));
}
}
' If an <anchor> element is rendered and an href
' attribute has not been defined, call the AddAttribute
' method to add an href attribute
' and set it to http://www.cohowinery.com.
' Use the EncodeUrl method to convert any spaces to %20.
If TagKey = HtmlTextWriterTag.A Then
If Not IsAttributeDefined(HtmlTextWriterAttribute.Href) Then
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"))
End If
End If
注釈
文字の URL エンコードは、パーセント記号 (%) の後に、文字の ISO-Latin コード ポイントの 2 桁の 16 進数表現 (大文字と小文字を区別しない) で構成されます。 スペースの 16 進数表現は 20 です。