What is the best way to escape HTML-specific characters in a string (PowerShell)?
html, html-escape-characters, powershell
Solution
There's a class that will do this in System.Web.
Add-Type -AssemblyName System.Web
[System.Web.HttpUtility]::HtmlEncode('something <somthing else>')
You can even go the other way:
[System.Web.HttpUtility]::HtmlDecode('something <something else>')
Problem
I'm generating some simple HTML with PowerShell script, and I would like to escape strings used in result HTML (since they can contain some HTML-specific symbols). For example: ``` $a = "something <somthing else>"; ``` should be converted to the following: ``` "something <something else>" ``` Is there any built-in function for that?