在字符串 (PowerShell) 中转义 HTML 特定字符的最佳方法是什么? [英] What is the best way to escape HTML-specific characters in a string (PowerShell)?
本文介绍了在字符串 (PowerShell) 中转义 HTML 特定字符的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PowerShell 脚本生成一些简单的 HTML,我想转义结果 HTML 中使用的字符串(因为它们可以包含一些特定于 HTML 的符号).
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).
例如:
$a = "something <somthing else>";
应转换为以下内容:
"something <something else>"
是否有任何内置函数?
推荐答案
System.Web 中有一个类可以执行此操作.
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>')
这篇关于在字符串 (PowerShell) 中转义 HTML 特定字符的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文