WebUtility.HtmlEncode Method (String)
Converts a string to an HTML-encoded string.
Assembly: System (in System.dll)
Parameters
- value
- Type: System.String
The string to encode.
If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. HTML encoding converts characters that are not allowed in HTML into character-entity equivalents; HTML decoding reverses the encoding. For example, when embedded in a block of text, the characters < and > are encoded as < and > for HTTP transmission.
If the value parameter is Nothing, then the returned encoded string is Nothing. If the value parameter is an empty string, then the returned encoded string is an empty string.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
<#
.SYNOPSIS
This script encodes and decodes an HTML String
.DESCRIPTION
This script used
.NOTES
File Name : Show-HtmlCoding.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell Version 2.0
.LINK
This script posted to:
http://www.pshscripts.blogspot.com
MSDN sample posted tot:
http://msdn.microsoft.com/en-us/library/ee388364.aspx
.EXAMPLE
PSH [C:\foo]: .\Show-HtmlCoding.ps1
Original String: <this is a string123> & so is this one??
Encoded String : <this is a string123> & so is this one??
Decoded String : <this is a string123> & so is this one??
Original string = Decoded string?: True
#>
# Create string to encode/decode
$Str = "<this is a string123> & so is this one??"
# Encode String
$Encstr = [System.Net.WebUtility]::HtmlEncode($str)
# Decode String
$Decstr = [System.Net.WebUtility]::HtmlDecode($EncStr)
# Display strings
"Original String: {0}" -f $Str
"Encoded String : {0}" -f $Encstr
"Decoded String : {0}" -f $Decstr
$eq = ($str -eq $Decstr)
"Original string = Decoded string?: {0}" -f $eq
- 9/27/2010
- Thomas Lee
