指定した URL 内の空白文字列を "%20" に変換して、最小限の URL エンコーディングを実行します。
名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Protected Function EncodeUrl ( _
url As String _
) As String
'使用
Dim url As String
Dim returnValue As String
returnValue = Me.EncodeUrl(url)
protected string EncodeUrl (
string url
)
protected:
String^ EncodeUrl (
String^ url
)
protected String EncodeUrl (
String url
)
protected function EncodeUrl (
url : String
) : String
適用できません。
パラメータ
- url
エンコードする URL を格納している文字列。
戻り値
エンコードされた URL を格納している文字列。
解説
文字の URL エンコーディングは、パーセント記号 (%) の後にその文字に対する ISO-Latin コード ポイントの 2 桁の 16 進数表現 (大文字と小文字を区別しない) が続く形式で表されます。空白文字の 16 進数表現は 20 です。
使用例
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 Then
If Not IsAttributeDefined(HtmlTextWriterAttribute.Href) Then
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"))
End If
End If
// 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 being 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 (get_TagKey().Equals(HtmlTextWriterTag.A)) {
if (!(IsAttributeDefined(HtmlTextWriterAttribute.Href))) {
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"));
}
}
プラットフォーム
Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
バージョン情報
.NET Framework
サポート対象 : 3.0,2.0,1.1,1.0
参照
関連項目
HtmlTextWriter クラス
HtmlTextWriter メンバ
System.Web.UI 名前空間
TextWriter
UrlPathEncode
AddAttribute
HttpRequest