c# - 如何在c#中转义字符串中的字符
问题描述
我有这个字符串,并得到一个错误
字符串文本 =
<root><Info id="inseID">17</Info><note><123comments></note></root>
我想把它转换成
<root><Info id="inseID">17</Info><note><123comments></note></root>
解决方案
使用 linq 到 xml。
var text = "<root><Info id=\"inseID\">17</Info><note></note></root>";
var xml = XElement.Parse(text);
xml.Element("note").Add("<123comments>");
//string result = xml.ToString(); // will be escaped
推荐阅读
- c - 传递给函数的数组和数组参数之间的C语言区别
- python - 使用具有相同 div 的 BeautifulSoup 进行 Web 解析 - 如果在页面上找不到,则无法返回“N/A”
- java - 在杰克逊代码中打印带有 2 位数秒的时间戳
- html - 是否有将内联样式转换为 css 类的包
- node.js - useQuery 返回未定义,但在 gql 操场上返回数据
- r - randomForest 包的功能重要性
- javascript - 如何从链表显示到控制台节点
- c++ - 并行小数组比并行大数组慢?
- oracle - 带有用户配置文件和角色的 Oracle 12c 导入转储
- json - Normalizr 更改原始文件 .json 或生成具有所需架构的新文件 .json?