Monday, 27 September 2010

Show-HtmlCoding.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script encodes and decodes an HTML String 
  4. .DESCRIPTION 
  5.     This script used  
  6. .NOTES 
  7.     File Name  : Show-HtmlCoding.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 2.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://www.pshscripts.blogspot.com 
  13.     MSDN sample posted tot: 
  14.         http://msdn.microsoft.com/en-us/library/ee388364.aspx 
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\Show-HtmlCoding.ps1 
  17.     Original String: <this is a string123> & so is this one?? 
  18.     Encoded String : &lt;this is a string123&gt; &amp; so is this one?? 
  19.     Decoded String : <this is a string123> & so is this one?? 
  20.     Original string = Decoded string?: True    
  21. #> 
  22.  
  23. # Create string to encode/decode 
  24. $Str = "<this is a string123> & so is this one??" 
  25.  
  26. # Encode String 
  27. $Encstr = [System.Net.WebUtility]::HtmlEncode($str
  28.  
  29. # Decode String 
  30. $Decstr = [System.Net.WebUtility]::HtmlDecode($EncStr
  31.  
  32. # Display strings 
  33. "Original String: {0}" -f $Str 
  34. "Encoded String : {0}" -f $Encstr 
  35. "Decoded String : {0}" -f $Decstr 
  36. $eq = ($str -eq $Decstr
  37. "Original string = Decoded string?: {0}" -f $eq  

No comments: